Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dev code for webpack compatibility #18

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 54 additions & 48 deletions map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,16 @@ var props = {
*/
dispatch: function(event, args) {
//!steal-remove-start
if (arguments.length > 4) {
canDev.warn('Arguments to dispatch should be an array, not multiple arguments.');
args = Array.prototype.slice.call(arguments, 1);
}
if(process.env.NODE_ENV !== 'production') {
if (arguments.length > 4) {
canDev.warn('Arguments to dispatch should be an array, not multiple arguments.');
args = Array.prototype.slice.call(arguments, 1);
}

if (args && !Array.isArray(args)) {
canDev.warn('Arguments to dispatch should be an array.');
args = [args];
if (args && !Array.isArray(args)) {
canDev.warn('Arguments to dispatch should be an array.');
args = [args];
}
}
//!steal-remove-end

Expand All @@ -232,8 +234,10 @@ var props = {
var meta = ensureMeta(this);

//!steal-remove-start
if (!event.reasonLog) {
event.reasonLog = [canReflect.getName(this), "dispatched", '"' + event.type + '"', "with"].concat(args);
if(process.env.NODE_ENV !== 'production') {
if (!event.reasonLog) {
event.reasonLog = [canReflect.getName(this), "dispatched", '"' + event.type + '"', "with"].concat(args);
}
}

if (typeof meta._log === "function") {
Expand Down Expand Up @@ -730,50 +734,52 @@ var symbols = {
*/
"can.getWhatIChange": function getWhatIChange(key) {
//!steal-remove-start
var whatIChange = {};
var meta = ensureMeta(this);

var notifyHandlers = [].concat(
meta.handlers.get([key, "event", "notify"]),
meta.handlers.get([key, "onKeyValue", "notify"])
);

var mutateHandlers = [].concat(
meta.handlers.get([key, "event", "mutate"]),
meta.handlers.get([key, "event", "domUI"]),
meta.handlers.get([key, "onKeyValue", "mutate"]),
meta.handlers.get([key, "onKeyValue", "domUI"])
);

if (notifyHandlers.length) {
notifyHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);

if (changes) {
var record = whatIChange.derive;
if (!record) {
record = (whatIChange.derive = {});
if(process.env.NODE_ENV !== 'production') {
var whatIChange = {};
var meta = ensureMeta(this);

var notifyHandlers = [].concat(
meta.handlers.get([key, "event", "notify"]),
meta.handlers.get([key, "onKeyValue", "notify"])
);

var mutateHandlers = [].concat(
meta.handlers.get([key, "event", "mutate"]),
meta.handlers.get([key, "event", "domUI"]),
meta.handlers.get([key, "onKeyValue", "mutate"]),
meta.handlers.get([key, "onKeyValue", "domUI"])
);

if (notifyHandlers.length) {
notifyHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);

if (changes) {
var record = whatIChange.derive;
if (!record) {
record = (whatIChange.derive = {});
}
mergeDependencyRecords(record, changes);
}
mergeDependencyRecords(record, changes);
}
});
}
});
}

if (mutateHandlers.length) {
mutateHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);
if (mutateHandlers.length) {
mutateHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);

if (changes) {
var record = whatIChange.mutate;
if (!record) {
record = (whatIChange.mutate = {});
if (changes) {
var record = whatIChange.mutate;
if (!record) {
record = (whatIChange.mutate = {});
}
mergeDependencyRecords(record, changes);
}
mergeDependencyRecords(record, changes);
}
});
}
});
}

return Object.keys(whatIChange).length ? whatIChange : undefined;
return Object.keys(whatIChange).length ? whatIChange : undefined;
}
//!steal-remove-end
},
"can.onPatches": function(handler, queue) {
Expand Down
92 changes: 53 additions & 39 deletions value/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,32 @@ var symbols = {
* @param {Any} oldValue The old value of the observable.
*/
"can.dispatch": function(value, old) {
queues.enqueueByQueue(
var queuesArgs = [];
queuesArgs = [
this.handlers.getNode([]),
this,
[value, old]
//!steal-remove-start
/* jshint laxcomma: true */
, null
, [canReflect.getName(this), "changed to", value, "from", old]
/* jshint laxcomma: false */
//!steal-remove-end
);
];

//!steal-remove-start
if (typeof this._log === "function") {
this._log(old, value);
if(process.env.NODE_ENV !== 'production') {
queuesArgs = [
this.handlers.getNode([]),
this,
[value, old]
/* jshint laxcomma: true */
, null
, [canReflect.getName(this), "changed to", value, "from", old]
/* jshint laxcomma: false */
];
}
//!steal-remove-end
queues.enqueueByQueue.apply(queues, queuesArgs);
//!steal-remove-start
if(process.env.NODE_ENV !== 'production') {
if (typeof this._log === "function") {
this._log(old, value);
}
}
//!steal-remove-end
},
Expand Down Expand Up @@ -184,43 +196,45 @@ var symbols = {
*/
"can.getWhatIChange": function getWhatIChange() {
//!steal-remove-start
var whatIChange = {};
if(process.env.NODE_ENV !== 'production') {
var whatIChange = {};

var notifyHandlers = this.handlers.get(["notify"]);
var mutateHandlers = [].concat(
this.handlers.get(["mutate"]),
this.handlers.get(["domUI"])
);
var notifyHandlers = this.handlers.get(["notify"]);
var mutateHandlers = [].concat(
this.handlers.get(["mutate"]),
this.handlers.get(["domUI"])
);

if (notifyHandlers.length) {
notifyHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);
if (notifyHandlers.length) {
notifyHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);

if (changes) {
var record = whatIChange.derive;
if (!record) {
record = (whatIChange.derive = {});
if (changes) {
var record = whatIChange.derive;
if (!record) {
record = (whatIChange.derive = {});
}
mergeDependencyRecords(record, changes);
}
mergeDependencyRecords(record, changes);
}
});
}
});
}

if (mutateHandlers.length) {
mutateHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);
if (mutateHandlers.length) {
mutateHandlers.forEach(function(handler) {
var changes = canReflect.getChangesDependencyRecord(handler);

if (changes) {
var record = whatIChange.mutate;
if (!record) {
record = (whatIChange.mutate = {});
if (changes) {
var record = whatIChange.mutate;
if (!record) {
record = (whatIChange.mutate = {});
}
mergeDependencyRecords(record, changes);
}
mergeDependencyRecords(record, changes);
}
});
}
});
}

return Object.keys(whatIChange).length ? whatIChange : undefined;
return Object.keys(whatIChange).length ? whatIChange : undefined;
}
//!steal-remove-end
},

Expand Down