Releases: Feavy/signal
Releases · Feavy/signal
v1.1.0
refactor: better nested batches handling
Use a counter instead of a boolean to count nested batches. Observers are triggered when the counter reaches 0.
feat: signal object's methods changes are batched
This prevent extra observer calls when a method modifies more than one property.
class Vec2 {
constructor(public x: number, public y: number) { }
public set(x: number, y: number) {
this.x = x;
this.y = y;
}
}
const pos = new Signal(new Vec2(0, 0));
observe(() => {
console.log("position:", pos.value.unwrapped);
}); // Prints: "position: { x: 0, y: 0 }"
pos.set(1, 2); // Prints: "position: { x: 1, y: 2 }" <-- the observer is called only once
feat: add signalify
function to transform any object into a reactive one
const position = {x: 0, y: 0 };
signalify(position);
observe(() => {
console.log("position:", (position as Signal<Vec2>).value.unwrapped);
}); // Prints: "position: { _x: 0, _y: 0 }"
(position as Signal<Vec2>).value = { x: 1, y: 2 }; // Prints: "position: { _x: 1, _y: 2 }"