diff --git a/can-simple-map.js b/can-simple-map.js index 9aa67ff..2a0888b 100644 --- a/can-simple-map.js +++ b/can-simple-map.js @@ -54,18 +54,28 @@ var SimpleMap = Construct.extend("SimpleMap", //!steal-remove-start - if (typeof this._log === "function") { - this._log(prop, value, old); + if (process.env.NODE_ENV !== 'production') { + if (typeof this._log === "function") { + this._log(prop, value, old); + } } //!steal-remove-end - - this.dispatch({ + + var dispatched = { keyChanged: !had ? prop : undefined, - type: prop, - //!steal-remove-start - reasonLog: [ canReflect.getName(this) + "'s", prop, "changed to", value, "from", old ], - //!steal-remove-end - }, [value, old]); + type: prop + }; + //!steal-remove-start + if (process.env.NODE_ENV !== 'production') { + dispatched = { + keyChanged: !had ? prop : undefined, + type: prop, + reasonLog: [ canReflect.getName(this) + "'s", prop, "changed to", value, "from", old ], + }; + } + //!steal-remove-end + + this.dispatch(dispatched, [value, old]); } } @@ -99,10 +109,11 @@ var SimpleMap = Construct.extend("SimpleMap", // pass a single property to only get logs for said property, e.g: `.log("foo")` log: function(key) { //!steal-remove-start - var quoteString = function quoteString(x) { - return typeof x === "string" ? JSON.stringify(x) : x; - }; - + if (process.env.NODE_ENV !== 'production') { + var quoteString = function quoteString(x) { + return typeof x === "string" ? JSON.stringify(x) : x; + }; + } var meta = ensureMeta(this); meta.allowedLogKeysSet = meta.allowedLogKeysSet || new Set(); @@ -128,7 +139,7 @@ var SimpleMap = Construct.extend("SimpleMap", eventQueue(SimpleMap.prototype); -canReflect.assignSymbols(SimpleMap.prototype,{ +var simpleMapProto = { // -type- "can.isMapLike": true, "can.isListLike": false, @@ -138,22 +149,32 @@ canReflect.assignSymbols(SimpleMap.prototype,{ "can.getKeyValue": SimpleMap.prototype.get, "can.setKeyValue": SimpleMap.prototype.set, "can.deleteKeyValue": function(prop) { + var dispatched; if( this._data.hasOwnProperty(prop) ) { var old = this._data[prop]; delete this._data[prop]; //!steal-remove-start - if (typeof this._log === "function") { - this._log(prop, undefined, old); + if (process.env.NODE_ENV !== 'production') { + if (typeof this._log === "function") { + this._log(prop, undefined, old); + } } //!steal-remove-end - this.dispatch({ + dispatched = { keyChanged: prop, - type: prop, - //!steal-remove-start - reasonLog: [ canReflect.getName(this) + "'s", prop, "deleted", old ], - //!steal-remove-end - }, [undefined, old]); + type: prop + }; + //!steal-remove-start + if (process.env.NODE_ENV !== 'production') { + dispatched = { + keyChanged: prop, + type: prop, + reasonLog: [ canReflect.getName(this) + "'s", prop, "deleted", old ] + }; + } + //!steal-remove-end + this.dispatch(dispatched, [undefined, old]); } }, @@ -182,14 +203,17 @@ canReflect.assignSymbols(SimpleMap.prototype,{ }, "can.getKeyDependencies": function(key) { return undefined; - }, + } +}; - //!steal-remove-start - "can.getName": function() { +//!steal-remove-start +if (process.env.NODE_ENV !== 'production') { + simpleMapProto["can.getName"] = function() { return canReflect.getName(this.constructor) + "{}"; - }, - //!steal-remove-end -}); + }; +} +//!steal-remove-end +canReflect.assignSymbols(SimpleMap.prototype,simpleMapProto); // Setup other symbols diff --git a/test/test.html b/test/test.html index c03f99c..f41e4da 100644 --- a/test/test.html +++ b/test/test.html @@ -1,3 +1,4 @@ + can-simple-map -
\ No newline at end of file +