From a00c4cfac17fff21d4da25fd6d1979758b0dbfd3 Mon Sep 17 00:00:00 2001 From: cherif BOUCHELAGHEM Date: Fri, 22 Jun 2018 13:12:29 +0100 Subject: [PATCH 1/2] fix dev code for webpack compatibility --- cache-requests/cache-requests.js | 4 +- .../constructor-hydrate.js | 4 +- can/map/map.js | 37 ++++++++++++------- can/merge/merge.js | 6 ++- constructor/callbacks-once/callbacks-once.js | 6 ++- constructor/store/store.js | 6 ++- data/callbacks-cache/callbacks-cache.js | 6 ++- data/callbacks/callbacks.js | 10 +++-- data/url/url.js | 12 ++++-- fall-through-cache/fall-through-cache.js | 6 ++- real-time/real-time.js | 15 +++++--- 11 files changed, 73 insertions(+), 39 deletions(-) diff --git a/cache-requests/cache-requests.js b/cache-requests/cache-requests.js index cbaae2b2..befb45a2 100644 --- a/cache-requests/cache-requests.js +++ b/cache-requests/cache-requests.js @@ -267,6 +267,8 @@ var cacheRequestsBehaviour = connect.behavior("cache-requests",function(baseConn module.exports = cacheRequestsBehaviour; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); +} module.exports = validate(cacheRequestsBehaviour, ['getListData', 'cacheConnection']); //!steal-remove-end \ No newline at end of file diff --git a/can/constructor-hydrate/constructor-hydrate.js b/can/constructor-hydrate/constructor-hydrate.js index c15af38d..c7196833 100644 --- a/can/constructor-hydrate/constructor-hydrate.js +++ b/can/constructor-hydrate/constructor-hydrate.js @@ -113,6 +113,8 @@ var constructorHydrateBehavior = connect.behavior("can-connect/can/construct-hyd module.exports = constructorHydrateBehavior; //!steal-remove-start -var validate = require('can-connect/helpers/validate'); +if(process.env.NODE_ENV !== 'production') { + var validate = require('can-connect/helpers/validate'); +} module.exports = validate(constructorHydrateBehavior, ['Map', 'List', 'instanceStore', 'hydrateInstance']); //!steal-remove-end \ No newline at end of file diff --git a/can/map/map.js b/can/map/map.js index 5a0f90b3..1bf13457 100644 --- a/can/map/map.js +++ b/can/map/map.js @@ -296,11 +296,15 @@ var canMapBehavior = connect.behavior("can/map",function(baseConnection){ */ updatedList: function(list, listData, set){ queues.batch.start(); - queues.mutateQueue.enqueue(baseConnection.updatedList, this, arguments,{ - //!steal-remove-start - reasonLog: ["set", set,"list", list,"updated with", listData] - //!steal-remove-end - }); + if(process.env.NODE_ENV !== 'production') { + queues.mutateQueue.enqueue(baseConnection.updatedList, this, arguments,{ + //!steal-remove-start + reasonLog: ["set", set,"list", list,"updated with", listData] + //!steal-remove-end + }); + } else { + queues.mutateQueue.enqueue(baseConnection.updatedList, this, arguments); + } queues.batch.stop(); }, @@ -442,8 +446,10 @@ canMapBehavior.callbackInstanceEvents = function (funcName, instance) { eventQueue.dispatch.call(instance, {type: funcName, target: instance}); //!steal-remove-start - if (this.id) { - dev.log("can-connect/can/map/map.js - " + (constructor.shortName || this.name) + " " + this.id(instance) + " " + funcName); + if(process.env.NODE_ENV !== 'production') { + if (this.id) { + dev.log("can-connect/can/map/map.js - " + (constructor.shortName || this.name) + " " + this.id(instance) + " " + funcName); + } } //!steal-remove-end @@ -802,11 +808,14 @@ var overwrite = function( connection, Constructor, overwrites) { module.exports = canMapBehavior; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate( - canMapBehavior, - [ - 'id', 'get', 'updatedList', 'destroy', 'save', 'getList' - ] -); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + + module.exports = validate( + canMapBehavior, + [ + 'id', 'get', 'updatedList', 'destroy', 'save', 'getList' + ] + ); +} //!steal-remove-end diff --git a/can/merge/merge.js b/can/merge/merge.js index 70fba717..769c1130 100644 --- a/can/merge/merge.js +++ b/can/merge/merge.js @@ -100,6 +100,8 @@ var mergeBehavior = connect.behavior("can/merge",function(baseConnection){ module.exports = mergeBehavior; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate(mergeBehavior, ['createdInstance', 'destroyedInstance', 'updatedInstance', 'updatedList']); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + module.exports = validate(mergeBehavior, ['createdInstance', 'destroyedInstance', 'updatedInstance', 'updatedList']); +} //!steal-remove-end \ No newline at end of file diff --git a/constructor/callbacks-once/callbacks-once.js b/constructor/callbacks-once/callbacks-once.js index 4b1641f7..e0eae4b5 100644 --- a/constructor/callbacks-once/callbacks-once.js +++ b/constructor/callbacks-once/callbacks-once.js @@ -94,6 +94,8 @@ var callbacksOnceBehavior = connect.behavior("constructor/callbacks-once",functi module.exports = callbacksOnceBehavior; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate(callbacksOnceBehavior, callbacks); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + module.exports = validate(callbacksOnceBehavior, callbacks); +} //!steal-remove-end \ No newline at end of file diff --git a/constructor/store/store.js b/constructor/store/store.js index f6d77558..1452aab2 100644 --- a/constructor/store/store.js +++ b/constructor/store/store.js @@ -766,6 +766,8 @@ constructorStore.requestCleanupDelay = 10; module.exports = constructorStore; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate(constructorStore, ['hydrateInstance', 'hydrateList', 'getList', 'get', 'save', 'destroy']); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + module.exports = validate(constructorStore, ['hydrateInstance', 'hydrateList', 'getList', 'get', 'save', 'destroy']); +} //!steal-remove-end diff --git a/data/callbacks-cache/callbacks-cache.js b/data/callbacks-cache/callbacks-cache.js index bb8543b7..b604bd46 100644 --- a/data/callbacks-cache/callbacks-cache.js +++ b/data/callbacks-cache/callbacks-cache.js @@ -133,6 +133,8 @@ var callbackCache = connect.behavior("data/callbacks-cache",function(baseConnect module.exports = callbackCache; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate(callbackCache, []); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + module.exports = validate(callbackCache, []); +} //!steal-remove-end \ No newline at end of file diff --git a/data/callbacks/callbacks.js b/data/callbacks/callbacks.js index c519d215..c260a47e 100644 --- a/data/callbacks/callbacks.js +++ b/data/callbacks/callbacks.js @@ -141,8 +141,10 @@ var dataCallbackBehavior = connect.behavior("data/callbacks",function(baseConnec module.exports = dataCallbackBehavior; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate(dataCallbackBehavior, [ - "getListData", "createData", "updateData", "destroyData" -]); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + module.exports = validate(dataCallbackBehavior, [ + "getListData", "createData", "updateData", "destroyData" + ]); +} //!steal-remove-end \ No newline at end of file diff --git a/data/url/url.js b/data/url/url.js index 6ad4ea4a..71bd4a31 100644 --- a/data/url/url.js +++ b/data/url/url.js @@ -326,8 +326,10 @@ var findContentType = function( url, method ) { return url.contentType; } else { //!steal-remove-start - dev.warn("Unacceptable contentType on can-connect request. " + - "Use 'application/json' or 'application/x-www-form-urlencoded'"); + if(process.env.NODE_ENV !== 'production') { + dev.warn("Unacceptable contentType on can-connect request. " + + "Use 'application/json' or 'application/x-www-form-urlencoded'"); + } //!steal-remove-end } } @@ -376,6 +378,8 @@ var makeAjax = function ( ajaxOb, data, type, ajax, contentType, reqOptions ) { module.exports = urlBehavior; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate(urlBehavior, ['url']); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + module.exports = validate(urlBehavior, ['url']); +} //!steal-remove-end diff --git a/fall-through-cache/fall-through-cache.js b/fall-through-cache/fall-through-cache.js index 97be5298..96184b16 100644 --- a/fall-through-cache/fall-through-cache.js +++ b/fall-through-cache/fall-through-cache.js @@ -289,6 +289,8 @@ var fallThroughCache = connect.behavior("fall-through-cache",function(baseConnec module.exports = fallThroughCache; //!steal-remove-start -var validate = require("can-connect/helpers/validate"); -module.exports = validate(fallThroughCache, ['hydrateList', 'hydrateInstance', 'getListData', 'getData']); +if(process.env.NODE_ENV !== 'production') { + var validate = require("can-connect/helpers/validate"); + module.exports = validate(fallThroughCache, ['hydrateList', 'hydrateInstance', 'getListData', 'getData']); +} //!steal-remove-end \ No newline at end of file diff --git a/real-time/real-time.js b/real-time/real-time.js index 4363c708..06df957d 100644 --- a/real-time/real-time.js +++ b/real-time/real-time.js @@ -134,8 +134,9 @@ var canDev = require('can-util/js/dev/dev'); module.exports = connect.behavior("real-time",function(baseConnection){ var createPromise = Promise.resolve(); + var behavior; - return { + behavior = { createData: function(){ var promise = baseConnection.createData.apply(this, arguments); var cleanPromise = promise.catch(function () { return ''; }) @@ -358,9 +359,11 @@ module.exports = connect.behavior("real-time",function(baseConnection){ return instance; }); } + }; - //!steal-remove-start - ,gotListData: function(items, set) { + //!steal-remove-start + if(process.env.NODE_ENV !== 'production') { + behavior.gotListData = function(items, set) { var self = this; if (this.algebra) { for(var item, i = 0, l = items.data.length; i < l; i++) { @@ -380,8 +383,10 @@ module.exports = connect.behavior("real-time",function(baseConnection){ return Promise.resolve(items); } - //!steal-remove-end - }; + } + //!steal-remove-end + + return behavior; }); var create = function(props){ From 49d62c7899aef7677e7df5827b6945187d492893 Mon Sep 17 00:00:00 2001 From: cherif BOUCHELAGHEM Date: Fri, 22 Jun 2018 15:44:56 +0100 Subject: [PATCH 2/2] fix args wrapping for debug/dev mode --- can/map/map.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/can/map/map.js b/can/map/map.js index 1bf13457..ee045957 100644 --- a/can/map/map.js +++ b/can/map/map.js @@ -296,15 +296,16 @@ var canMapBehavior = connect.behavior("can/map",function(baseConnection){ */ updatedList: function(list, listData, set){ queues.batch.start(); + var enqueueOptions = {}; + //!steal-remove-start if(process.env.NODE_ENV !== 'production') { - queues.mutateQueue.enqueue(baseConnection.updatedList, this, arguments,{ - //!steal-remove-start - reasonLog: ["set", set,"list", list,"updated with", listData] - //!steal-remove-end - }); - } else { - queues.mutateQueue.enqueue(baseConnection.updatedList, this, arguments); + enqueueOptions = { + reasonLog: ["set", set,"list", list,"updated with", listData] + }; } + //!steal-remove-end + + queues.mutateQueue.enqueue(baseConnection.updatedList, this, arguments, enqueueOptions); queues.batch.stop(); },