diff --git a/resolver/resolver-test.js b/resolver/resolver-test.js index d2a6692..2d5be51 100644 --- a/resolver/resolver-test.js +++ b/resolver/resolver-test.js @@ -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'); @@ -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"); +}); diff --git a/resolver/resolver.js b/resolver/resolver.js index 1ab263e..580a7b3 100644 --- a/resolver/resolver.js +++ b/resolver/resolver.js @@ -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),