From f7e015037ea2a5f754e9c50d477c93005ae8ea39 Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Tue, 5 Feb 2019 14:50:53 -0700 Subject: [PATCH 1/2] Ensure derive behaves consistently Fixes https://github.com/sveltejs/svelte/issues/2056 --- store.mjs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/store.mjs b/store.mjs index ffdd90bf0e..797b512704 100644 --- a/store.mjs +++ b/store.mjs @@ -66,7 +66,6 @@ export function derive(stores, fn) { const single = !Array.isArray(stores); if (single) stores = [stores]; - const auto = fn.length === 1; let value = {}; return readable(set => { @@ -78,7 +77,7 @@ export function derive(stores, fn) { const sync = () => { if (pending) return; const result = fn(single ? values[0] : values, set); - if (auto && (value !== (value = result))) set(result); + if (value !== (value = result)) set(result); } const unsubscribers = stores.map((store, i) => store.subscribe( From 6eefb4b6012c8244aa6cd11a4b875e66179cf59d Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Tue, 5 Feb 2019 15:12:14 -0700 Subject: [PATCH 2/2] Fixes to correct solution --- store.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/store.mjs b/store.mjs index 797b512704..10bdad3626 100644 --- a/store.mjs +++ b/store.mjs @@ -66,6 +66,7 @@ export function derive(stores, fn) { const single = !Array.isArray(stores); if (single) stores = [stores]; + const auto = fn.length < 2; let value = {}; return readable(set => { @@ -77,7 +78,7 @@ export function derive(stores, fn) { const sync = () => { if (pending) return; const result = fn(single ? values[0] : values, set); - if (value !== (value = result)) set(result); + if (auto && (value !== (value = result))) set(result); } const unsubscribers = stores.map((store, i) => store.subscribe(