Lint and format src/runtime/store/index.js

pull/8569/head
S. Elliott Johnson 3 years ago
parent 4e74b7de3c
commit efec4ef130

@ -1,4 +1,11 @@
import { run_all, subscribe, noop, safe_not_equal, is_function, get_store_value } from '../internal';
import {
run_all,
subscribe,
noop,
safe_not_equal,
is_function,
get_store_value
} from '../internal';
const subscriber_queue = [];
/**
* Creates a `Readable` store that allows reading by subscription.
@ -80,9 +87,7 @@ export function writable(value, start = noop) {
export function derived(stores, fn, initial_value) {
const single = !Array.isArray(stores);
/** @type {Array<Readable<any>>} */
const stores_array = single
? [stores]
: stores;
const stores_array = single ? [stores] : stores;
if (!stores_array.every(Boolean)) {
throw new Error('derived() expects stores as input, got a falsy value');
}
@ -100,20 +105,25 @@ export function derived(stores, fn, initial_value) {
const result = fn(single ? values[0] : values, set, update);
if (auto) {
set(result);
}
else {
} else {
cleanup = is_function(result) ? result : noop;
}
};
const unsubscribers = stores_array.map((store, i) => subscribe(store, (value) => {
const unsubscribers = stores_array.map((store, i) =>
subscribe(
store,
(value) => {
values[i] = value;
pending &= ~(1 << i);
if (started) {
sync();
}
}, () => {
},
() => {
pending |= 1 << i;
}));
}
)
);
started = true;
sync();
return function stop() {
@ -143,7 +153,6 @@ export function readonly(store) {
*/
export { get_store_value as get };
/**
* @typedef {(value: T) => void} Subscriber
* @template T

Loading…
Cancel
Save