You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7ca2dad
Browse filesBrowse the repository at this point in the historyBrowse files
<p>Write to the equation instead, <code>double := 4</code>, and the checker refuses it, in your editor and in CI:</p>
103
-
<preclass="err"><code>counter.rx:5:3 -error WRITE_TO_NON_SOURCE: double is an equation: only sources are written (W-1)</code></pre>
106
+
<preclass="err"><code><spanclass="eg">counter.rx:5:3 -</span><spanclass="eh">error WRITE_TO_NON_SOURCE</span>: double is an equation: only sources are written <spanclass="ed">(W-1)</span></code></pre>
104
107
105
108
<h2>Destructure props, keep them live</h2>
106
109
<p>In Solid, destructuring props reads them once and the component stops updating. In .rx, destructure them right in the parameter list: every name follows its prop, defaults and rest included, and the rest spreads onto an element as in JSX.</p>
@@ -131,7 +134,7 @@ <h2>Async is just <code>await</code></h2>
131
134
</section>
132
135
}</code></pre>
133
136
<p>There's a <code>loading</code> boundary but no <code>errored</code> one, so the checker says what's missing and how to fix it:</p>
134
-
<preclass="err"><code>profile.rx:10:7 -error UNHANDLED_FAILURE: a reader of user.name (in <Profile>) can fail with Error and no catch or errored boundary above it discharges Error — show it where it is read: `errored fallback(e) { … } { … }` around the reader (or `await … catch (e) => …` at the await, to make the rejection an answer) (R-f-5)</code></pre>
137
+
<preclass="err"><code><spanclass="eg">profile.rx:10:7 -</span><spanclass="eh">error UNHANDLED_FAILURE</span>: a reader of user.name (in <Profile>) can fail with Error and no catch or errored boundary above it discharges Error <spanclass="ef">—</span> show it where it is read: <spanclass="ec">`errored fallback(e) { … } { … }`</span> around the reader (or <spanclass="ec">`await … catch (e) => …`</span> at the await, to make the rejection an answer) <spanclass="ed">(R-f-5)</span></code></pre>
135
138
136
139
<h2>A like button, the first time you write it</h2>
137
140
<p>Show the new count at once, send it, and let the server's answer replace the guess. That's <code>guess</code>, which lowers to Solid's <code>createOptimistic</code>. This is how most people write it first:</p>
@@ -150,9 +153,9 @@ <h2>A like button, the first time you write it</h2>
<p>It has three bugs, and two only show when the network is slow or a request fails. The checker finds all three:</p>
153
-
<preclass="err"><code>like.rx:13:3 -error UNHANDLED_FAILURE: a reader of likes (in <Like>) can fail with Error and no catch or errored boundary above it discharges Error — show it where it is read: `errored fallback(e) { … } { … }` around the reader (or `await … catch (e) => …` at the await, to make the rejection an answer) (R-f-5)
154
-
like.rx:7:3 -error UNCAUGHT_ACTION_FAILURE: action send can fail with Error and does not catch it: a handler cannot (it does not await the action) — `try { … } catch (e) { … }` in the body (R-f-6)
155
-
like.rx:13:3 -error GUESS_WHILE_LOADING: <button> onClick starts `send`, which can run `guess likes` while likes is loading a new question (its question reads what the click reads): the guess composes on the previous answer, and the new answer replaces it, so the change disappears while it is out (D-34) — put the element inside the `loading` region whose content reads likes, or give it `disabled={pending? likes}`, or keep the pending change in a source of its own until it lands (AC-3a)</code></pre>
156
+
<preclass="err"><code><spanclass="eg">like.rx:13:3 -</span><spanclass="eh">error UNHANDLED_FAILURE</span>: a reader of likes (in <Like>) can fail with Error and no catch or errored boundary above it discharges Error <spanclass="ef">—</span> show it where it is read: <spanclass="ec">`errored fallback(e) { … } { … }`</span> around the reader (or <spanclass="ec">`await … catch (e) => …`</span> at the await, to make the rejection an answer) <spanclass="ed">(R-f-5)</span></code>
157
+
<code><spanclass="eg">like.rx:7:3 -</span><spanclass="eh">error UNCAUGHT_ACTION_FAILURE</span>: action send can fail with Error and does not catch it: a handler cannot (it does not await the action) <spanclass="ef">—</span><spanclass="ec">`try { … } catch (e) { … }`</span> in the body <spanclass="ed">(R-f-6)</span></code>
158
+
<code><spanclass="eg">like.rx:13:3 -</span><spanclass="eh">error GUESS_WHILE_LOADING</span>: <button> onClick starts <spanclass="ec">`send`</span>, which can run <spanclass="ec">`guess likes`</span> while likes is loading a new question (its question reads what the click reads): the guess composes on the previous answer, and the new answer replaces it, so the change disappears while it is out <spanclass="ed">(D-34)</span><spanclass="ef">—</span> put the element inside the <spanclass="ec">`loading`</span> region whose content reads likes, or give it <spanclass="ec">`disabled={pending? likes}`</span>, or keep the pending change in a source of its own until it lands <spanclass="ed">(AC-3a)</span></code></pre>
156
159
<p>The last one is the subtle one. Click while the count is still reloading and your +1 lands on the old answer, then vanishes when the new one arrives. Each error names the fix, and the fixed version passes:</p>
157
160
<preclass="ok"><spanclass="fname">like.rx</span><code><spanclass="k">export default component</span> Like(props: { id: number }) {
@@ -180,15 +183,15 @@ <h3>The "Saving…" that never shows</h3>
180
183
<spanclass="k">let</span> r = <spanclass="k">await</span> saveName(<spanclass="s">"Ann"</span>) <spanclass="k">catch</span> (e) => e.message
181
184
status := r
182
185
}}>{status}</button></code></pre>
183
-
<preclass="err"><code>save.rx:5:3 -error HELD_WRITE: status := … comes before an `await` in a body that is an action because it writes and awaits (AC-1b), so it is held until the body ends (AC-1): for state that shows while the work runs, `guess status := …` (a source with a question, ST-5c); for a reset that lands now, `onFlush(() => { status := … })`(EF-8); to hold it on purpose, declare the action (`action name() { … }`); or write it after the `await`(AC-1c)</code></pre>
186
+
<preclass="err"><code><spanclass="eg">save.rx:5:3 -</span><spanclass="eh">error HELD_WRITE</span>: status := … comes before an <spanclass="ec">`await`</span> in a body that is an action because it writes and awaits <spanclass="ed">(AC-1b)</span>, so it is held until the body ends <spanclass="ed">(AC-1)</span>: for state that shows while the work runs, <spanclass="ec">`guess status := …`</span> (a source with a question, <spanclass="ed">ST-5c</span>); for a reset that lands now, <spanclass="ec">`onFlush(() => { status := … })`</span><spanclass="ed">(EF-8)</span>; to hold it on purpose, declare the action (<spanclass="ec">`action name() { … }`</span>); or write it after the <spanclass="ec">`await`</span><spanclass="ed">(AC-1c)</span></code></pre>
184
187
<h3>The write that undoes another click</h3>
185
188
<p>Read, await, write back. If anything changed <code>tags</code> in between, this overwrites it.</p>
<spanclass="k">let</span> saved = <spanclass="k">await</span> addTag(t) <spanclass="k">catch</span> (e) => t
189
192
tags := before + <spanclass="s">" "</span> + saved
190
193
}</code></pre>
191
-
<preclass="err"><code>tags.rx:5:3 -error STALE_WRITE_BACK: tags := … after an `await` is computed from tags as it was read before that `await`: whatever changed tags in between (another action, a reload) is overwritten — write functionally (`tags := v => …`, W-6), which applies to tags as it stands at the write, or guess it (`guess`, AC-3) and let the answer replace the guess (AC-1e)</code></pre>
194
+
<preclass="err"><code><spanclass="eg">tags.rx:5:3 -</span><spanclass="eh">error STALE_WRITE_BACK</span>: tags := … after an <spanclass="ec">`await`</span> is computed from tags as it was read before that <spanclass="ec">`await`</span>: whatever changed tags in between (another action, a reload) is overwritten <spanclass="ef">—</span> write functionally (<spanclass="ec">`tags := v => …`</span>, <spanclass="ed">W-6</span>), which applies to tags as it stands at the write, or guess it (<spanclass="ec">`guess`</span>, <spanclass="ed">AC-3</span>) and let the answer replace the guess <spanclass="ed">(AC-1e)</span></code></pre>
0 commit comments