From a7265f65e3ad2ea0d8d02343f5a9e5aca1b36873 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 6 May 2019 06:26:38 -0400 Subject: [PATCH] use safe_not_equal logic for derived stores - fixes #2644 --- store.mjs | 2 +- test/store/index.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/store.mjs b/store.mjs index 9f8cdf0c48..bc9bc46ed1 100644 --- a/store.mjs +++ b/store.mjs @@ -55,7 +55,7 @@ export function derived(stores, fn, initial_value) { const sync = () => { if (pending) return; const result = fn(single ? values[0] : values, set); - if (auto && (value !== (value = result))) set(result); + if (auto) set(result); }; const unsubscribers = stores.map((store, i) => store.subscribe( diff --git a/test/store/index.js b/test/store/index.js index d7c1e76668..44617d6d00 100644 --- a/test/store/index.js +++ b/test/store/index.js @@ -188,6 +188,29 @@ describe('store', () => { unsubscribe(); }); + + it('is updated with safe_not_equal logic', () => { + const arr = [0]; + + const number = writable(1); + const numbers = derived(number, $number => { + arr[0] = $number; + return arr; + }); + + const concatenated = []; + + const unsubscribe = numbers.subscribe(value => { + concatenated.push(...value); + }); + + number.set(2); + number.set(3); + + assert.deepEqual(concatenated, [1, 2, 3]); + + unsubscribe(); + }); }); describe('get', () => {