store.ts without dependencies

pull/2832/head
Sander Hahn 6 years ago
parent d548a5a5f4
commit ed9a32fd7d

@ -94,26 +94,21 @@ export default [
{ {
file: `store.mjs`, file: `store.mjs`,
format: 'esm', format: 'esm',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
}, },
{ {
file: `store.js`, file: `store.js`,
format: 'cjs', format: 'cjs',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
} }
], ],
plugins: [ plugins: [
is_publish is_publish
? typescript({ ? typescript({
include: 'src/**',
exclude: 'src/internal/**',
typescript: require('typescript') typescript: require('typescript')
}) })
: sucrase({ : sucrase({
transforms: ['typescript'] transforms: ['typescript']
}) })
], ]
external: id => id.startsWith('svelte/')
}, },
// everything else // everything else

@ -1,4 +1,10 @@
import { run_all, noop, safe_not_equal, is_function } from './internal/utils'; /** Safe not equal. */
function safe_not_equal(a: any, b: any) {
return a !== a ? b === b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
/** No operation. */
function noop() { }
/** Callback to inform of a value updates. */ /** Callback to inform of a value updates. */
type Subscriber<T> = (value: T) => void; type Subscriber<T> = (value: T) => void;
@ -143,7 +149,7 @@ export function derived<T, S extends Stores>(
if (auto) { if (auto) {
set(result as T); set(result as T);
} else { } else {
cleanup = is_function(result) ? result as Unsubscriber : noop; cleanup = result instanceof Function ? result as Unsubscriber : noop;
} }
}; };
@ -164,7 +170,7 @@ export function derived<T, S extends Stores>(
sync(); sync();
return function stop() { return function stop() {
run_all(unsubscribers); unsubscribers.forEach((unsubscribe) => unsubscribe());
cleanup(); cleanup();
}; };
}); });

Loading…
Cancel
Save