Skip to content

Commit 45cd960

Browse files
authored
Merge pull request sveltejs#2310 from sveltejs/sveltejsgh-2296
update readable signature to match writable
2 parents 70c8d3e + f3cb540 commit 45cd960

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

store.mjs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { run_all, noop, get_store_value, safe_not_equal } from './internal';
22

3-
export function readable(start, value) {
4-
const { set, subscribe } = writable(value, () => start(set));
5-
return { subscribe };
3+
export function readable(value, start) {
4+
return {
5+
subscribe: writable(value, start).subscribe
6+
};
67
}
78

89
export function writable(value, start = noop) {
@@ -25,7 +26,7 @@ export function writable(value, start = noop) {
2526
function subscribe(run, invalidate = noop) {
2627
const subscriber = [run, invalidate];
2728
subscribers.push(subscriber);
28-
if (subscribers.length === 1) stop = start() || noop;
29+
if (subscribers.length === 1) stop = start(set) || noop;
2930
run(value);
3031

3132
return () => {
@@ -45,7 +46,7 @@ export function derive(stores, fn) {
4546
const auto = fn.length < 2;
4647
let value = {};
4748

48-
return readable(set => {
49+
return readable(undefined, set => {
4950
let inited = false;
5051
const values = [];
5152

test/store/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('store', () => {
6666
let running;
6767
let tick;
6868

69-
const store = readable(set => {
69+
const store = readable(undefined, set => {
7070
tick = set;
7171
running = true;
7272

@@ -192,7 +192,7 @@ describe('store', () => {
192192

193193
describe('get', () => {
194194
it('gets the current value of a store', () => {
195-
const store = readable(() => {}, 42);
195+
const store = readable(42, () => {});
196196
assert.equal(get(store), 42);
197197
});
198198
});

0 commit comments

Comments
 (0)