Skip to content

Commit

Permalink
using can-simple-value for getters using lastSetValue
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipskevin committed Sep 26, 2017
1 parent 783fd1f commit 4419b0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions can-define.js
Expand Up @@ -22,6 +22,7 @@ var ns = require("can-namespace");
var canSymbol = require("can-symbol");
var canReflect = require("can-reflect");
var singleReference = require("can-util/js/single-reference/single-reference");
var simpleObervable = require("can-simple-observable");

var eventsProto, define,
make, makeDefinition, replaceWith, getDefinitionsAndMethods,
Expand Down Expand Up @@ -54,10 +55,10 @@ var eachPropertyDescriptor = function(map, cb){
function trapSets(observableValue) {
return {
observable: observableValue,
lastSetValue: undefined,
lastSetValue: simpleObervable(),
setValue: function(value) {
// Hold on to this value for next time.
this.lastSetValue = value;
canReflect.setValue(this.lastSetValue, value);
if(this.observable) {
if(canSymbol.for("can.setValue") in this.observable) {
canReflect.setValue(this.observable, value);
Expand Down Expand Up @@ -329,17 +330,17 @@ make = {
computeFn, valueTrap, computeObj;

var boundGet = function() {
return get.call(map, computeObj.valueTrap.lastSetValue);
return get.call(map, canReflect.getValue(computeObj.valueTrap.lastSetValue));
};

if(get.length < 1) {
if(get.length < 2) {
if(defaultValue && defaultValue.isComputed) {
computeFn = defaultValue;
valueTrap = trapSets(computeFn);
} else {
computeFn = new Observation(boundGet, map);
valueTrap = trapSets(computeFn);
valueTrap.lastSetValue = defaultValue;
canReflect.setValue(valueTrap.lastSetValue, defaultValue);
}
} else {
if (defaultValue) {
Expand Down Expand Up @@ -563,7 +564,7 @@ make = {
lastSet: function(prop) {
return function() {
var lastSetValue = this._computed[prop].valueTrap.lastSetValue;
return lastSetValue;
return canReflect.getValue(lastSetValue);
};
}
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -38,6 +38,7 @@
"can-namespace": "^1.0.0",
"can-observation": "^3.3.4",
"can-reflect": "^1.2.1",
"can-simple-observable": "^1.0.0",
"can-symbol": "^1.0.0",
"can-types": "^1.1.0",
"can-util": "^3.9.0"
Expand Down

0 comments on commit 4419b0f

Please sign in to comment.