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