fast reactive signals jsr.io/@mary/signals
typescript jsr
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at trunk 39 lines 823 B view raw view rendered
1# signals 2 3[JSR](https://jsr.io/@mary/signals) | [source code](https://tangled.sh/mary.my.id/pkg-signals) 4 5fast reactive signals. 6 7```ts 8const name = signal(`Mary`); 9 10// run a side effect that gets rerun on state changes... 11effect(() => { 12 console.log(`Hello, ${name.value}!`); 13}); 14// logs `Hello, Mary!` 15 16// combine multiple writes into a single update... 17batch(() => { 18 name.value = `Elly`; 19 name.value = `Alice!`; 20}); 21// logs `Hello, Alice!` 22 23// run derivations that only gets updated as needed when not depended on... 24const doubled = computed(() => { 25 console.log(`Computation ran!`); 26 return name.repeat(2); 27}); 28 29doubled.value; 30// logs `Computation ran!` 31// -> `AliceAlice` 32 33name.value = `Alina`; 34// no logs as it's not being read under an effect yet! 35 36doubled.value; 37// logs `Computation ran!` 38// -> `AlinaAlina` 39```