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', () => {