Skip to content

Commit

Permalink
Wrap debug code in process.env checks
Browse files Browse the repository at this point in the history
  • Loading branch information
chasenlehara committed Jun 29, 2018
1 parent e4c2ac7 commit 77263e6
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions can-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ module.exports = {
};

//!steal-remove-start
var objectName = canReflect.getName(object);
Object.defineProperty(observationFunction, "name", {
value: "ValueFrom<" + objectName + "." + keyPath + ">"
});
if (process.env.NODE_ENV !== 'production') {
var objectName = canReflect.getName(object);
Object.defineProperty(observationFunction, "name", {
value: "ValueFrom<" + objectName + "." + keyPath + ">"
});
}
//!steal-remove-end

return new Observation(observationFunction);
Expand All @@ -27,36 +29,41 @@ module.exports = {
var observable = keyObservable(object, keyPath);

//!steal-remove-start
canReflect.assignSymbols(observable.onDependencyChange, {
"can.getChangesDependencyRecord": function getChangesDependencyRecord() {
// can-simple-observable/key/ creates an observation that walks along
// the keyPath. In doing so, it implicitly registers the objects and
// keys along the path as mutators of the observation; this means
// getDependencyDataOf(...an object and key along the path) returns
// whatIChange.derive.valueDependencies = [observable], which is not
// true! The observable does not derive its value from the objects
// along the keyPath. By implementing getChangesDependencyRecord and
// returning undefined, calls to can.getWhatIChange() for any objects
// along the keyPath will not include the observable.
}
});
if (process.env.NODE_ENV !== 'production') {
canReflect.assignSymbols(observable.onDependencyChange, {
"can.getChangesDependencyRecord": function getChangesDependencyRecord() {
// can-simple-observable/key/ creates an observation that walks along
// the keyPath. In doing so, it implicitly registers the objects and
// keys along the path as mutators of the observation; this means
// getDependencyDataOf(...an object and key along the path) returns
// whatIChange.derive.valueDependencies = [observable], which is not
// true! The observable does not derive its value from the objects
// along the keyPath. By implementing getChangesDependencyRecord and
// returning undefined, calls to can.getWhatIChange() for any objects
// along the keyPath will not include the observable.
}
});
}
//!steal-remove-end

return canReflect.assignSymbols(observable, {

var symbolsToAssign = {
// Remove the getValue symbol so the observable is only a setter
"can.getValue": null,
"can.getValue": null
};

//!steal-remove-start
"can.getValueDependencies": function getValueDependencies() {
//!steal-remove-start
if (process.env.NODE_ENV !== 'production') {
symbolsToAssign["can.getValueDependencies"] = function getValueDependencies() {
// Normally, getDependencyDataOf(observable) would include
// whatChangesMe.derive.keyDependencies, and it would contain
// the object and anything along keyPath. This symbol returns
// undefined because this observable does not derive its value
// from the object or anything along the keyPath, it only
// mutates the last object in the keyPath.
}
//!steal-remove-end
});
};
}
//!steal-remove-end

return canReflect.assignSymbols(observable, symbolsToAssign);
}
};

0 comments on commit 77263e6

Please sign in to comment.