S icon indicating copy to clipboard operation
S copied to clipboard

Compute value with prev != next check

Open oleggrishechkin opened this issue 2 years ago • 0 comments

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

oleggrishechkin avatar Jan 12 '22 19:01 oleggrishechkin