|
|
|
@ -1,15 +1,16 @@
|
|
|
|
|
import { run_all, noop, get_store_value } from './internal';
|
|
|
|
|
import { run_all, noop, get_store_value, safe_not_equal } from './internal';
|
|
|
|
|
|
|
|
|
|
export function readable(start, value) {
|
|
|
|
|
const subscribers = [];
|
|
|
|
|
let stop;
|
|
|
|
|
|
|
|
|
|
function set(newValue) {
|
|
|
|
|
if (newValue === value) return;
|
|
|
|
|
value = newValue;
|
|
|
|
|
function set(new_value) {
|
|
|
|
|
if (safe_not_equal(value, new_value)) {
|
|
|
|
|
value = new_value;
|
|
|
|
|
subscribers.forEach(s => s[1]());
|
|
|
|
|
subscribers.forEach(s => s[0](value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
subscribe(run, invalidate = noop) {
|
|
|
|
@ -38,12 +39,13 @@ export function writable(value, start = noop) {
|
|
|
|
|
let stop;
|
|
|
|
|
const subscribers = [];
|
|
|
|
|
|
|
|
|
|
function set(newValue) {
|
|
|
|
|
if (newValue === value) return;
|
|
|
|
|
value = newValue;
|
|
|
|
|
function set(new_value) {
|
|
|
|
|
if (safe_not_equal(value, new_value)) {
|
|
|
|
|
value = new_value;
|
|
|
|
|
subscribers.forEach(s => s[1]());
|
|
|
|
|
subscribers.forEach(s => s[0](value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function update(fn) {
|
|
|
|
|
set(fn(value));
|
|
|
|
|