mali-signali
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "mali-signali", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Aleksandar Ružičić", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -122,2 +122,43 @@ # `mali-signali` | ||
In addition to canceling via the returned function, effects can be canceled via an instance of `AbortSignal`. | ||
```ts | ||
import { signal, effect } from 'mali-signali'; | ||
const [a, setA] = signal(1); | ||
const [b, setB] = signal(2); | ||
const abortController = new AbortController(); | ||
effect(() => { console.log(a()); }, { signal: abortController.signal }); // logs '1' | ||
effect(() => { console.log(b()); }, { signal: abortController.signal }); // logs '2' | ||
setA(3); // logs '3' | ||
setB(4); // logs '4' | ||
abortController.abort(); | ||
setA(5); // nothing happens | ||
setB(6); // nothing happens | ||
``` | ||
## Untracked reads | ||
For cases where you need to read the value of a signal without tracking it as a dependency, you can call the reader function via `untracked()`. | ||
```ts | ||
import { signal, effect, untracked } from 'mali-signali'; | ||
const [a, setA] = signal(1); | ||
const [b, setB] = signal(2); | ||
effect(() => { | ||
setA(untracked(a) + b()); // effect reads but does not depend on 'a' | ||
}); | ||
setB(3); | ||
console.log(a()); // 6 | ||
``` | ||
## Batching | ||
@@ -124,0 +165,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
97732
33
213