Example #1
0
	it('should call the given mapper\'s map patch with all the non-default values in the range', asyncgen.async(function*(){
	    var myDispMap = Object.create(dispMap);
	    var keys = [];
	    var values = [];
	    dispMap.myMapper = {
		init: function*() {},
		map: function*(ctx, p, u) {
		    keys.push(p.key);
		    values.push(p.value);
		    return [];
		},
	    };
	    var ostore = new vercast.DummyObjectStore(new vercast.ObjectDispatcher(myDispMap));
	    var v = yield* ostore.init('Treap', {elementType: 'atom', args:  {value: ''}});
	    v = (yield* ostore.trans(v, {_type: 'set', _key: 5, from: '', to: 'a'})).v;
	    v = (yield* ostore.trans(v, {_type: 'set', _key: ['foo', 'bar'], from: '', to: 'b'})).v;
	    v = (yield* ostore.trans(v, {_type: 'set', _key: ['foo', 'baz'], from: '', to: 'c'})).v;
	    v = (yield* ostore.trans(v, {_type: 'set', _key: ['foo', []], from: '', to: 'd'})).v;
	    var mapper = yield* ostore.init('myMapper', {});
	    v = (yield* ostore.trans(v, {_type: '_remap', 
					 mapper: mapper, 
					 keyFrom: ['foo'] /*inclusive*/, 
					 keyTo: ['foo', []] /*exclusive*/})).v;
	    assert.deepEqual(keys, [['foo', 'bar'], ['foo', 'baz']]);
	    assert.deepEqual(values, ['b', 'c']);
	}));
Example #2
0
	it('should effect the patches that are returned by the mapper', asyncgen.async(function*(){
	    var myDispMap = Object.create(dispMap);
	    var keys = [];
	    var values = [];
	    dispMap.myMapper = {
		init: function*() {},
		map: function*(ctx, p, u) {
		    var patches = [];
		    if(p.value !== '') {
			patches.push({_type: 'somePatch',
				      value: p.value});
		    }
		    return patches;
		},
	    };
	    var ostore = new vercast.DummyObjectStore(new vercast.ObjectDispatcher(myDispMap));
	    var v = yield* ostore.init('Treap', {elementType: 'atom', args:  {value: ''}});
	    v = (yield* ostore.trans(v, {_type: 'set', _key: ['foo', 'bar'], from: '', to: 'b'})).v;
	    v = (yield* ostore.trans(v, {_type: 'set', _key: ['foo', 'baz'], from: '', to: 'c'})).v;
	    var mapper = yield* ostore.init('myMapper', {});
	    var eff = (yield* ostore.trans(v, {_type: '_remap', 
					       mapper: mapper, 
					       keyFrom: ['foo'], 
					       keyTo: ['foo', []]})).eff;
	    var seq = ostore.getSequenceStore();
	    yield* seq.append(eff);
	    assert.deepEqual(yield* seq.shift(), {_type: 'somePatch', value: 'b'});
	    assert.deepEqual(yield* seq.shift(), {_type: 'somePatch', value: 'c'});
	}));