Skip to content

Commit

Permalink
Merge pull request #64 from canjs/fix-webpack-debug-style
Browse files Browse the repository at this point in the history
fix dev code for webpack compatibility
  • Loading branch information
chasenlehara committed Jul 4, 2018
2 parents 12ac4ae + 901392a commit 6c2d071
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
80 changes: 52 additions & 28 deletions can-simple-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

}
Expand Down Expand Up @@ -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();

Expand All @@ -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,
Expand All @@ -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]);
}
},

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/test.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!doctype html>
<title>can-simple-map</title>
<script src="../node_modules/steal/steal.js" main="test/test"></script>
<div id="qunit-fixture"></div>
<div id="qunit-fixture"></div>

0 comments on commit 6c2d071

Please sign in to comment.