Skip to content

Commit

Permalink
use safe_not_equal logic for derived stores - fixes #2644
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed May 6, 2019
1 parent 43f82af commit a7265f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion store.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions test/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit a7265f6

Please sign in to comment.