|
|
|
@ -71,17 +71,16 @@ export function writable<T>(value: T, start: StartStopNotifier<T> = noop): Writa
|
|
|
|
|
value = new_value;
|
|
|
|
|
if (stop) { // store is ready
|
|
|
|
|
const run_queue = !subscriber_queue.length;
|
|
|
|
|
for (let i = 0; i < subscribers.length; i++) {
|
|
|
|
|
for (let i = 0; i < subscribers.length; i += 1) {
|
|
|
|
|
const s = subscribers[i];
|
|
|
|
|
s[1]();
|
|
|
|
|
subscriber_queue.push(s, value);
|
|
|
|
|
}
|
|
|
|
|
if (run_queue) {
|
|
|
|
|
let s;
|
|
|
|
|
while (s = subscriber_queue.shift()) {
|
|
|
|
|
const val = subscriber_queue.shift();
|
|
|
|
|
s[0](val);
|
|
|
|
|
for (let i = 0; i < subscriber_queue.length; i += 2) {
|
|
|
|
|
subscriber_queue[i][0](subscriber_queue[i + 1]);
|
|
|
|
|
}
|
|
|
|
|
subscriber_queue.length = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -141,7 +140,7 @@ export function derived<T, S extends Stores>(
|
|
|
|
|
|
|
|
|
|
const auto = fn.length < 2;
|
|
|
|
|
|
|
|
|
|
const store = readable(initial_value, (set) => {
|
|
|
|
|
return readable(initial_value, (set) => {
|
|
|
|
|
let inited = false;
|
|
|
|
|
const values: StoresValues<S> = [] as StoresValues<S>;
|
|
|
|
|
|
|
|
|
@ -182,10 +181,4 @@ export function derived<T, S extends Stores>(
|
|
|
|
|
cleanup();
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
subscribe(run: Subscriber<T>, invalidate: Invalidator<T> = noop): Unsubscriber {
|
|
|
|
|
return store.subscribe(run, invalidate);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|