adamhaile / S

S.js - Simple, Clean, Fast Reactive Programming in Javascript
MIT License
1.31k stars 68 forks source link

Compute value with prev != next check #46

Open oleggrishechkin opened 2 years ago

oleggrishechkin commented 2 years ago

Hi, how can I create a computed value (with prev != next checking similar to S.value)?

const computed = S(() => compute());

And I need to run all relative computations only if value that compute returns was changed, but code above run all relative computations even if compute returns the same value.

Possible solution:

let computed;

S(() => {
    if (!computed) {
        computed = S.value(compute());
    } else {
        computed(compute());
    }
});

It works as I expected, but it's too large and maybe S exists same functionality out of the box