Skip to content

Commit

Permalink
prevents the resolver function from leaking observable reads
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed Jun 5, 2018
1 parent 0d0e2e7 commit 895ba81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions resolver/resolver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var mapEventMixin = require("can-event-queue/map/map");
var canSymbol = require("can-symbol");
var canReflect = require("can-reflect");
var Observation = require("can-observation");
var ObservationRecorder = require("can-observation-recorder");

QUnit.module('can-simple-observable/resolver');

Expand Down Expand Up @@ -249,3 +250,24 @@ QUnit.test("proactive binding doesn't last past binding (can-stache#486)", funct
QUnit.equal(readCount, 0, "internal observation only updated once");

});

QUnit.test("reading observables does not leak the observable read", function(){
// if an observation is listening is reading this value, the value
// should not ObservationRecorder.add its deps
// there is a similar test in can-define

var v = new SimpleObservable(2);

var obs = new ResolverObservable(function(value) {
value.resolve( canReflect.getValue(v));
});

ObservationRecorder.start();

obs.on(function(){});

var records = ObservationRecorder.stop();

QUnit.equal(records.keyDependencies.size, 0, "there are no key dependencies");
QUnit.equal(records.valueDependencies.size, 0, "there are no valueDependencies");
});
3 changes: 2 additions & 1 deletion resolver/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var SimpleObservable = require("../can-simple-observable");
var getChangesSymbol = canSymbol.for("can.getChangesDependencyRecord");

function ResolverObservable(resolver, context) {
this.resolver = resolver;
// we don't want reads leaking out. We should be binding to all of this ourselves.
this.resolver = ObservationRecorder.ignore(resolver);
this.context = context;
this.valueOptions = {
resolve: this.resolve.bind(this),
Expand Down

0 comments on commit 895ba81

Please sign in to comment.