0.0.11 • Published 2 years ago

@mkja/signals v0.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Signals

Implementation of signals pattern

npm i @mkja/signals
import { Signal, Derived, effect, batch } from "@mkja/signal";

const factor0 = new Signal(0); // @type {Signal<number>}
const factor1 = new Signal(0); // @type {Signal<number>}

//Type of dervied is based on return type of the callback function
const product = new Derived(() => factor0.value * factor1.value); // @type {Derived<number>}

//Effect when product is notify becouse signal.peek() is called on factor0/1 to get a peek of the value without adding the dependencies of the effect
effect(() => {
  console.log(`${factor0.peek()} * ${factor1.peek()} = ${product.value}`);
});

// Updates to signals inside batch runs dependent effets only once even if multiple signals is part of an effect
batch(() => {
  // Calls above effect only once
  factor0.value = 2;
  factor1.value = 3;
});
0.1.1

2 years ago

0.1.0

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.1

2 years ago