Add Dataflow.Graph.newScope.
This commit is contained in:
parent
8b63c68673
commit
ba2f4d677d
|
@ -98,6 +98,12 @@ Graph.prototype.defineObservableProperty = function (obj, prop, value, options)
|
||||||
return objectId;
|
return objectId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Graph.newScope = function (o) {
|
||||||
|
function O() {}
|
||||||
|
O.prototype = o;
|
||||||
|
return new O();
|
||||||
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
module.exports.Graph = Graph;
|
module.exports.Graph = Graph;
|
||||||
|
|
|
@ -129,3 +129,57 @@ describe('DerivedCell', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('scopes', function () {
|
||||||
|
var g = new Dataflow.Graph();
|
||||||
|
g.enforceSubjectPresence = false;
|
||||||
|
|
||||||
|
function buildScopes() {
|
||||||
|
var rootScope = {};
|
||||||
|
var midScope = Dataflow.Graph.newScope(rootScope);
|
||||||
|
var outerScope = Dataflow.Graph.newScope(midScope);
|
||||||
|
return {root: rootScope, mid: midScope, outer: outerScope};
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should make rootward props visible further out', function () {
|
||||||
|
var ss = buildScopes();
|
||||||
|
g.defineObservableProperty(ss.root, 'p', 123);
|
||||||
|
expect(ss.root.p).to.be(123);
|
||||||
|
expect(ss.mid.p).to.be(123);
|
||||||
|
expect(ss.outer.p).to.be(123);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should make changes at root visible at leaves', function () {
|
||||||
|
var ss = buildScopes();
|
||||||
|
g.defineObservableProperty(ss.root, 'p', 123);
|
||||||
|
expect(ss.outer.p).to.be(123);
|
||||||
|
ss.root.p = 234;
|
||||||
|
expect(ss.root.p).to.be(234);
|
||||||
|
expect(ss.outer.p).to.be(234);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should make changes at leaves visible at root', function () {
|
||||||
|
var ss = buildScopes();
|
||||||
|
g.defineObservableProperty(ss.root, 'p', 123);
|
||||||
|
expect(ss.outer.p).to.be(123);
|
||||||
|
ss.outer.p = 234;
|
||||||
|
expect(ss.root.p).to.be(234);
|
||||||
|
expect(ss.outer.p).to.be(234);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hide definitions at leaves from roots', function () {
|
||||||
|
var ss = buildScopes();
|
||||||
|
g.defineObservableProperty(ss.outer, 'p', 123);
|
||||||
|
expect(ss.outer.p).to.be(123);
|
||||||
|
expect(ss.mid.p).to.be(undefined);
|
||||||
|
expect(ss.root.p).to.be(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hide middle definitions from roots but show to leaves', function () {
|
||||||
|
var ss = buildScopes();
|
||||||
|
g.defineObservableProperty(ss.mid, 'p', 123);
|
||||||
|
expect(ss.outer.p).to.be(123);
|
||||||
|
expect(ss.mid.p).to.be(123);
|
||||||
|
expect(ss.root.p).to.be(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue