From 934727f551138eb1e16434fc38a95f4f86619672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Bon=C4=8Do?= Date: Sun, 19 May 2024 23:19:57 +0200 Subject: [PATCH 1/3] Update README.md Improves readability especially for beginners. * When comparing, using `===` instead of `==` is just a good practice. Additionally, stops reader from questions "Can this be null or undefined? Do I need to read docs?". * Changing `let` to `const` separates things that change from those that don't change, so reader don't have to keep in mind all variables. * Adding extra brackets to `for` emphasis there is a code on the same line and reader should not jump directly to the next line. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2c01eae..d84e885 100644 --- a/README.md +++ b/README.md @@ -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(); }); w.watch(c); c.get(); return () => { destructor?.(); w.unwatch(c) }; From 3925e15e4688bc5ad090d4bd447c91f99f3db5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Bon=C4=8Do?= Date: Mon, 20 May 2024 00:07:38 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d84e885..25df113 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,9 @@ const w = new Signal.subtle.Watcher(() => { pending = true; queueMicrotask(() => { pending = false; - for (let s of w.getPending()) { s.get(); } + for (let s of w.getPending()) { + s.get(); + } w.watch(); }); } From 2a032f225a13bbe3cf0ea1f4ad43f9045394574e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Bon=C4=8Do?= Date: Mon, 20 May 2024 00:09:28 +0200 Subject: [PATCH 3/3] Fixes indentation in a sample code --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 25df113..17c7de0 100644 --- a/README.md +++ b/README.md @@ -361,7 +361,7 @@ const w = new Signal.subtle.Watcher(() => { queueMicrotask(() => { pending = false; for (let s of w.getPending()) { - s.get(); + s.get(); } w.watch(); });