Merge pull request #2310 from sveltejs/gh-2296

update readable signature to match writable
pull/2319/head
Rich Harris 6 years ago committed by GitHub
commit 45cd960568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,8 +1,9 @@
import { run_all, noop, get_store_value, safe_not_equal } from './internal'; import { run_all, noop, get_store_value, safe_not_equal } from './internal';
export function readable(start, value) { export function readable(value, start) {
const { set, subscribe } = writable(value, () => start(set)); return {
return { subscribe }; subscribe: writable(value, start).subscribe
};
} }
export function writable(value, start = noop) { export function writable(value, start = noop) {
@ -25,7 +26,7 @@ export function writable(value, start = noop) {
function subscribe(run, invalidate = noop) { function subscribe(run, invalidate = noop) {
const subscriber = [run, invalidate]; const subscriber = [run, invalidate];
subscribers.push(subscriber); subscribers.push(subscriber);
if (subscribers.length === 1) stop = start() || noop; if (subscribers.length === 1) stop = start(set) || noop;
run(value); run(value);
return () => { return () => {
@ -45,7 +46,7 @@ export function derive(stores, fn) {
const auto = fn.length < 2; const auto = fn.length < 2;
let value = {}; let value = {};
return readable(set => { return readable(undefined, set => {
let inited = false; let inited = false;
const values = []; const values = [];

@ -66,7 +66,7 @@ describe('store', () => {
let running; let running;
let tick; let tick;
const store = readable(set => { const store = readable(undefined, set => {
tick = set; tick = set;
running = true; running = true;
@ -192,7 +192,7 @@ describe('store', () => {
describe('get', () => { describe('get', () => {
it('gets the current value of a store', () => { it('gets the current value of a store', () => {
const store = readable(() => {}, 42); const store = readable(42, () => {});
assert.equal(get(store), 42); assert.equal(get(store), 42);
}); });
}); });

Loading…
Cancel
Save