diff --git a/spec/dependentObservableBehaviors.js b/spec/dependentObservableBehaviors.js index 52e6b9067..2589726cb 100644 --- a/spec/dependentObservableBehaviors.js +++ b/spec/dependentObservableBehaviors.js @@ -15,6 +15,11 @@ describe('Dependent Observable', function() { expect(ko.isComputed(instance)).toEqual(true); }); + it('Should advertise that instances are not pure computed', function () { + var instance = ko.computed(function () { }); + expect(ko.isPureComputed(instance)).toEqual(false); + }); + it('Should advertise that instances cannot have values written to them', function () { var instance = ko.computed(function () { }); expect(ko.isWriteableObservable(instance)).toEqual(false); diff --git a/spec/observableBehaviors.js b/spec/observableBehaviors.js index 476377a9b..31c312c6e 100644 --- a/spec/observableBehaviors.js +++ b/spec/observableBehaviors.js @@ -10,6 +10,11 @@ describe('Observable', function() { expect(ko.isObservable(instance)).toEqual(true); }); + it('Should advertise that instances are not pure computed', function () { + var instance = ko.observable(); + expect(ko.isPureComputed(instance)).toEqual(false); + }); + it('Should be able to write values to it', function () { var instance = new ko.observable(); instance(123); diff --git a/spec/pureComputedBehaviors.js b/spec/pureComputedBehaviors.js index 49d31fc1d..84ad389b1 100644 --- a/spec/pureComputedBehaviors.js +++ b/spec/pureComputedBehaviors.js @@ -5,6 +5,11 @@ describe('Pure Computed', function() { expect(ko.isComputed(computed)).toEqual(true); }); + it('Should advertise that instances are pure computed', function () { + var instance = ko.pureComputed(function () { }); + expect(ko.isPureComputed(instance)).toEqual(true); + }); + it('Should require an evaluator function as constructor param', function () { expect(function () { ko.pureComputed(); }).toThrow(); }); diff --git a/src/subscribables/dependentObservable.js b/src/subscribables/dependentObservable.js index 22f799f98..49119c110 100644 --- a/src/subscribables/dependentObservable.js +++ b/src/subscribables/dependentObservable.js @@ -440,9 +440,15 @@ ko.isComputed = function (instance) { return ko.hasPrototype(instance, ko.computed); }; +ko.isPureComputed = function (instance) { + return ko.hasPrototype(instance, ko.computed) && + instance.getVersion === pureComputedOverrides.getVersion; +} + ko.exportSymbol('computed', ko.computed); ko.exportSymbol('dependentObservable', ko.computed); // export ko.dependentObservable for backwards compatibility (1.x) ko.exportSymbol('isComputed', ko.isComputed); +ko.exportSymbol('isPureComputed', ko.isPureComputed); ko.exportSymbol('computed.fn', computedFn); ko.exportProperty(computedFn, 'peek', computedFn.peek); ko.exportProperty(computedFn, 'dispose', computedFn.dispose);