From 1ce374c84e23f7aea0d80ba56e45c1a0bf2ea46b Mon Sep 17 00:00:00 2001 From: cherif BOUCHELAGHEM Date: Tue, 26 Jun 2018 22:41:25 +0100 Subject: [PATCH 1/2] fix dev code for webpack compatibility --- can-simple-map.js | 80 ++++++++++++++++++++++++++++++----------------- test/test.html | 3 +- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/can-simple-map.js b/can-simple-map.js index 506e1a2..d231a82 100644 --- a/can-simple-map.js +++ b/can-simple-map.js @@ -53,18 +53,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]); } } @@ -98,10 +108,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(); @@ -127,7 +138,7 @@ var SimpleMap = Construct.extend("SimpleMap", eventQueue(SimpleMap.prototype); -canReflect.assignSymbols(SimpleMap.prototype,{ +var simpleMapProto = { // -type- "can.isMapLike": true, "can.isListLike": false, @@ -137,22 +148,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]); } }, @@ -181,14 +202,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[canSymbol.for("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 +
From 901392a159a583aaaaab127a96b5df6f0890caf2 Mon Sep 17 00:00:00 2001 From: cherif BOUCHELAGHEM Date: Wed, 27 Jun 2018 20:33:42 +0100 Subject: [PATCH 2/2] fix can-symbol use after review --- can-simple-map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-simple-map.js b/can-simple-map.js index d231a82..e350d43 100644 --- a/can-simple-map.js +++ b/can-simple-map.js @@ -207,7 +207,7 @@ var simpleMapProto = { //!steal-remove-start if (process.env.NODE_ENV !== 'production') { - simpleMapProto[canSymbol.for("can.getName")] = function() { + simpleMapProto["can.getName"] = function() { return canReflect.getName(this.constructor) + "{}"; }; }