store
store copied to clipboard
Derived Stores
This PR implements an initial Derived
class implementation:
const count = new Store(10);
const doubleCount = new Derived([count], () => {
return count.state * 2;
})
doubleCount.subscribe(() => console.log(doubleCount.state));
count.setState(() => 20);
This Derived implementation even solves the diamond problem:
Where writes to "a" will call "d" twice (with a flicker of incorrect data known as a "Glitch") because of the dual-derived nature. Our implementation does not have this problem and therefore can be considered "glitch-free"
This is a push-based/hot signals implementation
Benchmarks
Due to the relatively naive nature of this code (I wrote it in one night at ~midnight) there are performance implication in using this. Namely, in our benchmarks we are a far cry from Angular or Solid's implementation, but come close to Vue's implementation: