remove combineStores

pull/954/head
Rich Harris 7 years ago
parent 96eac06e2d
commit d5d1eccb28

@ -150,25 +150,4 @@ assign(Store.prototype, {
}
});
function combineStores(children, store) {
if (!store) store = new Store();
var updates = {};
function addChild(key) {
var child = children[key];
updates[key] = child.get();
child.onchange(function(state) {
var update = {};
update[key] = state;
store.set(update);
});
}
for (var key in children) addChild(key);
store.set(updates);
return store;
}
export { Store, combineStores };
export { Store };

@ -1,7 +1,7 @@
import assert from 'assert';
import { Store, combineStores } from '../../store.js';
describe.only('store', () => {
describe('store', () => {
describe('get', () => {
it('gets a specific key', () => {
const store = new Store({
@ -143,51 +143,4 @@ describe.only('store', () => {
}, /'bar' is a read-only property/);
});
});
describe('combineStores', () => {
it('merges stores', () => {
const a = new Store({
x: 1,
y: 2
});
a.compute('z', ['x', 'y'], (x, y) => x + y);
const b = new Store({
x: 3,
y: 4
});
b.compute('z', ['x', 'y'], (x, y) => x + y);
const c = combineStores({ a, b });
c.compute('total', ['a', 'b'], (a, b) => a.z + b.z);
assert.deepEqual(c.get(), {
a: {
x: 1,
y: 2,
z: 3
},
b: {
x: 3,
y: 4,
z: 7
},
total: 10
});
const values = [];
c.observe('total', total => {
values.push(total);
});
a.set({ x: 2, y: 3 });
b.set({ x: 5, y: 6 });
assert.deepEqual(values, [10, 12, 16]);
});
});
});

Loading…
Cancel
Save