mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-29 00:22:05 +01:00
Merge pull request #2695 from sveltejs/gh-2644
use safe_not_equal logic for derived stores
This commit is contained in:
commit
4962e20aa2
@ -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(
|
||||
|
@ -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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user