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

Loading…
Cancel
Save