return readable store directly form derived, avoid .shift()

pull/3219/head
Rich Harris 6 years ago committed by GitHub
parent 419e40d3be
commit 95b2a72007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);
}
};
}

Loading…
Cancel
Save