update readable signature to match writable - fixes #2296

pull/2310/head
Richard Harris 6 years ago
parent d1536b21a2
commit f3cb540ce6

@ -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