Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should be a shortcut for calling the static Collection.merge() function on each key individually', () => {
const list = Collection()
.addInstance({foo: most.just(1), bar: most.just(10)})
.addInstance({foo: most.just(2), bar: most.just(20)});
const list$ = most.just(list);
const sinks1 = Collection.merge(['foo', 'bar'], list$);
const sinks2 = {
foo: Collection.merge('foo', list$),
bar: Collection.merge('bar', list$)
};
const p1foo = run(sinks1.foo).tick(1);
const p1bar = run(sinks1.bar).tick(1);
const p2foo = run(sinks2.foo).tick(1);
const p2bar = run(sinks2.bar).tick(1);
return Promise.all([p1foo, p1bar, p2foo, p2bar])
.then(results => {
assert.deepEqual(results.slice(0, 2), results.slice(2, 4));
});
});
it('should propagate the first error emitted by an active item stream', () => {
const list = Collection().addInstance({foo: most.throwError(new Error('test-error'))});
const list$ = switchCollection(['foo'], most.just(list));
const env = run(list$);
return env.tick(1)
.then(result => {
assert(result.error && result.error.message === 'test-error');
});
});
function init() {
const list = Collection()
.setInstance('a', {foo: most.just(1).continueWith(() => most.just(4).delay(3)), bar: most.just(3).delay(2)})
.setInstance('b', {foo: most.just(2).continueWith(() => most.just(5).delay(10))});
const stream = snapshot(switchCollection(['foo', 'bar'], most.never().startWith(list)));
return run(stream);
}
it('should reflect changes made to the list in the emitted object', () => {
const list1 = Collection()
.setInstance('x', {foo: most.just(1), bar: most.just(100)})
.setInstance('y', {foo: most.just(7).concat(most.just(5).delay(2)), bar: most.just(101)})
.setInstance('z', {foo: most.just(3).concat(most.just(2).delay(3)), bar: most.just(102)});
const list2 = list1
.setInstance('k', {foo: most.just(4), bar: most.just(103)})
.setInstance('y', {foo: most.just(33), bar: most.just(104)});
const list$ = most.just(list1).concat(most.just(list2).delay(2));
const stream = Collection.combineObject(['foo', 'bar'], list$);
const env = run(stream);
return env.tick(1)
.then(result => {
assert(result.events.length === 1);
assert.deepEqual(result.events[0], {
x: {foo: 1, bar: 100},
y: {foo: 7, bar: 101},
z: {foo: 3, bar: 102}
it('should reflect changes made to the list in the emitted array', () => {
const list1 = Collection()
.setInstance('x', {foo: most.just(1)})
.setInstance('y', {foo: most.just(7).concat(most.just(5).delay(2))})
.setInstance('z', {foo: most.just(3).concat(most.just(2).delay(3))});
const list2 = list1
.setInstance('k', {foo: most.just(4)})
.setInstance('y', {foo: most.just(33)});
const list$ = most.just(list1).concat(most.just(list2).delay(2));
const stream = Collection.combineArray('foo', list$);
const env = run(stream);
return env.tick(1)
.then(result => {
assert(result.events.length === 1);
assert.deepEqual(result.events[0], [1, 7, 3]);
return env.tick(1);
})
.then(result => {
assert(result.events.length === 1);
assert.deepEqual(result.events[0], [1, 33, 3, 4]);
return env.tick(1);
describe('when the arguments have differences', () => {
const last = {a: most.empty(), b: most.just(1), c: most.just('c')};
const next = {a: last.a, b: most.just(2), d: most.just('d')};
function run() {
return compareSinks(null, last, next);
}
it('should return an array of tuples', () => {
const result = run();
assert(Array.isArray(result));
assert(result.every(t => Array.isArray(t) && t.length === 2));
});
it('should specify the sink key for the first value in each tuple', () => {
const result = run();
assert(result.length === 3);
assert(result.findIndex(t => t[0] === 'b') !== -1);
assert(result.findIndex(t => t[0] === 'c') !== -1);
it('should not emit data from sinks that did not match the specified keys', () => {
const list$ = most.just(list);
const sinks = Collection.merge(['none', 'zero'], list$);
const env1 = run(sinks.none);
const env2 = run(sinks.zero);
return env1.tick(1)
.then(result => {
assert(result.events.length === 0);
assert(result.end);
return env2.tick(1);
})
.then(result => {
assert(result.events.length === 0);
assert(result.end);
});
});
});
function init(throwError) {
const errorFor = id => throwError ? new Error('test-error:' + id) : void 0;
const list = Collection()
.setInstance('a', {foo: count(0, 1), bar: count(10, 4, errorFor('a:bar')), baz: count(20)})
.setInstance('b', {foo: count(30, 2), bar: count(40, 2), baz: count(50)})
.setInstance('c', {foo: count(60, 3, errorFor('c:foo')), bar: count(70, 1), baz: count(80)});
const list2 = list.remove('c');
const list$ = most.just(list2).delay(1).startWith(list);
const data$ = switchCollection(['foo', 'bar'], list$).filter(ev => !ev.list);
return run(data$);
}
it('should not trigger a subsequent emission until each of the replaced sinks have emitted their first value', () => {
const sinks = {foo: most.just(1), bar: most.just(10)};
const list1 = Collection().setInstance('a', sinks);
const list2 = list1.setInstance('a', {foo: sinks.foo, bar: most.just(20).delay(3)});
const list$ = most.just(list1).concat(most.just(list2).delay(2));
const stream = snapshot(switchCollection(['foo', 'bar'], list$));
const env = run(stream);
return env.tick(1)
.then(result => {
assert(result.events.length === 1);
const changes = result.events[0].toArray().map(m => m.toJS());
assert.deepEqual(changes, [
{itemKey: 'a', index: 0, sinks: {foo: 1, bar: 10}}
]);
assert(!result.end);
return env.tick(5);
})
.then(result => {
assert(result.events.length === 1);
const changes = result.events[0].toArray().map(m => m.toJS());
assert.deepEqual(changes, [
function electronStoreSource () {
return most.just(store.store).multicast()
}