make autosubscribing to a nullish store a no-op (#2181)

pull/4304/head
Conduitry 6 years ago
parent 1a343b165c
commit a2b3560efe

@ -43,12 +43,15 @@ export function not_equal(a, b) {
}
export function validate_store(store, name) {
if (!store || typeof store.subscribe !== 'function') {
if (store != null && typeof store.subscribe !== 'function') {
throw new Error(`'${name}' is not a store with a 'subscribe' method`);
}
}
export function subscribe(store, ...callbacks) {
if (store == null) {
return noop;
}
const unsub = store.subscribe(...callbacks);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}

Loading…
Cancel
Save