-
Notifications
You must be signed in to change notification settings - Fork 69
Improves readability of code examples #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ const setCounter = (value) => { | |
| render(); | ||
| }; | ||
|
|
||
| const isEven = () => (counter & 1) == 0; | ||
| const isEven = () => (counter & 1) === 0; | ||
| const parity = () => isEven() ? "even" : "odd"; | ||
| const render = () => element.innerText = parity(); | ||
|
|
||
|
|
@@ -75,7 +75,7 @@ To understand Signals, let's take a look at the above example, re-imagined with | |
|
|
||
| ```js | ||
| const counter = new Signal.State(0); | ||
| const isEven = new Signal.Computed(() => (counter.get() & 1) == 0); | ||
| const isEven = new Signal.Computed(() => (counter.get() & 1) === 0); | ||
| const parity = new Signal.Computed(() => isEven.get() ? "even" : "odd"); | ||
|
|
||
| // A library or framework defines effects based on other Signal primitives | ||
|
|
@@ -355,12 +355,12 @@ The `Watcher` interface defined above gives the basis for implementing typical J | |
| // NOTE: This scheduling logic is too basic to be useful. Do not copy/paste. | ||
| let pending = false; | ||
|
|
||
| let w = new Signal.subtle.Watcher(() => { | ||
| const w = new Signal.subtle.Watcher(() => { | ||
| if (!pending) { | ||
| pending = true; | ||
| queueMicrotask(() => { | ||
| pending = false; | ||
| for (let s of w.getPending()) s.get(); | ||
| for (let s of w.getPending()) { s.get(); } | ||
| w.watch(); | ||
| }); | ||
| } | ||
|
|
@@ -370,7 +370,7 @@ let w = new Signal.subtle.Watcher(() => { | |
| // itself on the microtask queue whenever one of its dependencies might change | ||
| export function effect(cb) { | ||
| let destructor; | ||
| let c = new Signal.Computed(() => { destructor?.(); destructor = cb(); }); | ||
| const c = new Signal.Computed(() => { destructor?.(); destructor = cb(); }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same should we go multiline here ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I know this is sort of personal taste, but in my opinion this is acceptable. Lambda functions are often one-liners and the content in this case is not too complex. I assume a reader is used to reading the rest of the line. Understanding the purpose of the code is going to be the issue, but not its style. |
||
| w.watch(c); | ||
| c.get(); | ||
| return () => { destructor?.(); w.unwatch(c) }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.