diff --git a/js/src/dataflow.js b/js/src/dataflow.js index af06642..f8f3aeb 100644 --- a/js/src/dataflow.js +++ b/js/src/dataflow.js @@ -9,6 +9,7 @@ function Graph() { this.edgesReverse = Immutable.Map(); this.damagedNodes = Immutable.Set(); this.currentSubjectId = null; + this.enforceSubjectPresence = true; this.observablePropertyCounter = 0; } @@ -30,6 +31,8 @@ Graph.prototype.recordObservation = function (objectId) { if (this.currentSubjectId) { this.edgesForward = MapSet.add(this.edgesForward, objectId, this.currentSubjectId); this.edgesReverse = MapSet.add(this.edgesReverse, this.currentSubjectId, objectId); + } else if (this.enforceSubjectPresence) { + throw new Error('Attempt to observe ' + objectId + ' with no currentSubjectId'); } }; diff --git a/js/test/test-dataflow.js b/js/test/test-dataflow.js index 8cea7c2..d025e22 100644 --- a/js/test/test-dataflow.js +++ b/js/test/test-dataflow.js @@ -50,6 +50,7 @@ describe('dataflow edges, damage and subjects', function () { describe('DerivedCell', function () { describe('simple case', function () { var g = new Dataflow.Graph(); + g.enforceSubjectPresence = false; var c = DerivedCell(g, 'c', function () { return 123; }); var d = DerivedCell(g, 'd', function () { return c.value * 2; }); it('should be properly initialized', function () { @@ -78,6 +79,7 @@ describe('DerivedCell', function () { describe('a more complex case', function () { var g = new Dataflow.Graph(); + g.enforceSubjectPresence = false; function add(a, b) { return a + b; } var xs = new Cell(g, Immutable.List.of(1, 2, 3, 4), 'xs');