JSFiddle - React, Tailwind, and code Playground
by dgeb
HTML
<script src="https://rawgit.com/orbitjs/bower-orbit/master/orbit.js"></script>
<script src="https://rawgit.com/orbitjs/bower-orbit/master/orbit-common.js"></script>
JavaScript
Orbit.Promise = Promise;
var schema = new OC.Schema({
idField: 'id',
models: {
test: {
attributes: {
id: {
type: 'string'
},
protocol: {
type: 'string'
},
}
},
}
})
var counter = 0;
var LoggingSource = OC.MemorySource.extend({
_transform: function(op) {
//console.log('['+ this.id + '(_transform)]', op.op, op.path.join('.'), op.value);
// short circuit inf loop
if (counter++ > 10) {
return;
}
return this._super.apply(this, arguments);
}
});
function logCache(op) {
console.log('['+ this.id + '(cache)]', op.op, op.path.join('.'), op.value);
}
var source1 = new LoggingSource(schema);
source1.id = 1;
source1._cache.on('didTransform', logCache.bind(source1));
var source2 = new LoggingSource(schema);
source2.id = 2;
source2._cache.on('didTransform', logCache.bind(source2));
var TC = Orbit.TransformConnector.extend({
filterFunction: function(op) {
// console.log('[connection]', op.op, op.path.join('.'), op.value);
return true;
}
});
new TC(source1, source2);
new TC(source2, source1);
source1.transform({
op: 'add',
path: ['test','123123'],
value: source2.normalize('test', { protocol: 'test' })
});
source1.transform({
op: 'replace',
path: ['test', '123123', 'protocol'],
value: '123123'
});
source1.settleTransforms().then(console.log.bind(console, 'transformed'));