From af7f9765014173baa6ca0a9fa73de5a4e1d654c1 Mon Sep 17 00:00:00 2001 From: Jan Muehlemann Date: Wed, 29 May 2013 13:50:57 +0200 Subject: [PATCH] publish new version --- Jakefile.js | 2 +- backboneCQRS-0.5.5.min.js | 5 ----- backboneCQRS-0.5.5.js => backboneCQRS-0.5.6.js | 2 +- backboneCQRS-0.5.6.min.js | 5 +++++ package.json | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 backboneCQRS-0.5.5.min.js rename backboneCQRS-0.5.5.js => backboneCQRS-0.5.6.js (99%) create mode 100644 backboneCQRS-0.5.6.min.js diff --git a/Jakefile.js b/Jakefile.js index 1092b27..5997147 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -8,7 +8,7 @@ task('build', [], function(debug) { // a basic smoosh configuration object smoosh.config({ - "VERSION": "0.5.5", + "VERSION": "0.5.6", "JAVASCRIPT": { "DIST_DIR": "./", "backboneCQRS": [ diff --git a/backboneCQRS-0.5.5.min.js b/backboneCQRS-0.5.5.min.js deleted file mode 100644 index 4ca118c..0000000 --- a/backboneCQRS-0.5.5.min.js +++ /dev/null @@ -1,5 +0,0 @@ -// Backbone.CQRS.js -// (c) 2012 Jan Mühlemann -// Backbone.CQRS may be freely distributed under the MIT license. - -(function(){var e=this,t=e.Backbone;t.CQRS={};var n=e._,r=e.jQuery||e.Zepto,i=r.noop;t.CQRS.Message=t.Model.extend({url:i,fetch:i,save:i,destroy:i});var s=t.CQRS.Message.extend({});t.CQRS.Command=t.CQRS.Message.extend({emit:function(e){e&&this.observe(e),t.CQRS.hub.emit(t.CQRS.hub.commandsChannel,this.parse(this.toJSON()))},parse:function(e){return e},observe:function(e){t.CQRS.eventHandler.observe(this.id,e)}});var o=t.CQRS.hub={commandsChannel:"commands",defaults:{commandsChannel:"commands",eventsChannel:"events",eventNameAttr:"name",eventModelIdAttr:"payload.id",eventResponseToCommandId:"commandId"},init:function(e){var t=this;this.initialized||(this.initialized=!0,e=n.extend(this.defaults,e),e.parseEvent&&(this.parseEvent=e.parseEvent),e.getCommandId&&(this.getCommandId=e.getCommandId),this.commandsChannel=e.commandsChannel,this.on(e.eventsChannel,function(n){var r=new s;r.set(this.parseEvent(n));var i=r.toJSON();r.name=f(i,e.eventNameAttr),r.id=f(i,e.eventModelIdAttr),r.cmdId=t.getCommandId(i,e.eventResponseToCommandId),this.emit("dispatchEvent",r)}))},parseEvent:function(e){var t=e;return typeof t=="string"&&(t=JSON.parse(t)),t},getCommandId:function(e,t){return f(e,t)}};n.extend(o,t.Events),o.on=o.bind,o.emit=o.trigger,t.CQRS.EventDenormalizer=function(e){e=e||{},e.forEvent&&(this.forEvent=e.forEvent),e.forModel&&(this.forModel=e.forModel),e.payloadValue&&(this.payloadValue=e.payloadValue),e.modelIdAttr&&(this.modelIdAttr=e.modelIdAttr),e.onHandle&&(this.onHandle=e.onHandle),this.methode=e.methode||"update",this.model=e.model,this.collection=e.collection,this.forEvent&&this.forModel&&this.register.apply(this),this.initialize.apply(this,arguments)},n.extend(t.CQRS.EventDenormalizer.prototype,t.Events,{defaultPayloadValue:"payload",initialize:i,handle:function(e){if(this.methode!=="create"){var t=this.modelIdAttr?f(e.toJSON(),this.modelIdAttr):e.id;t&&this.trigger("change:"+t,this.parse(e),this.apply(this.methode))}else{var n=typeof this.collection=="function"?this.collection(e):this.collection;if(!n)return;var r=this.parse(e);n.add(r),this.onHandle&&this.onHandle(r,n.get(r.id))}},apply:function(e){var t=this;return function(n,r){e==="delete"?(r.isCQRSBound&&r.unbindCQRS(),r.destroy(),t.onHandle&&t.onHandle(n,r)):(r.set(n),t.onHandle&&t.onHandle(n,r))}},parse:function(e){return this.payloadValue||this.defaultPayloadValue?(diveTo=this.payloadValue||this.defaultPayloadValue,f(e.toJSON(),diveTo)):e.toJSON()},register:function(e,n){this.forEvent=e||this.forEvent,this.forModel=n||this.forModel,t.CQRS.eventHandler.register(this)}}),t.CQRS.EventDenormalizer.extend=t.Model.extend;var u=t.CQRS.EventDenormalizer.extend({initialize:function(){this.denormalizers=[],this.observedCommands=[],t.CQRS.hub.on("dispatchEvent",function(e){this.handle(e)},this)},getDenormalizer:function(e,t){return e?n(this.denormalizers).filter(function(t){return t.forEvent==e}):t?n(this.denormalizers).filter(function(e){return e.forModel==t}):null},handle:function(e){var t=this.getDenormalizer(e.name);n(t).each(function(t){t.handle(e)});var r=this.getPendingCommand(e);r&&(r.callback(e),this.removePendingCommand(r))},bind:function(e,t,r){if(e.indexOf(":")<0)return!1;var i=e.substring(0,e.indexOf(":")),s="change:"+e.substring(e.indexOf(":")+1,e.length),o=this.getDenormalizer(null,i);n(o).each(function(e){e.bind(s,t,r)})},unbind:function(e,t){if(e.indexOf(":")<0)return!1;var r=e.split(":"),i=r[0],s="change:"+r[1],o=this.getDenormalizer(null,i);n(o).each(function(e){e.unbind(s,t)})},observe:function(e,t){this.observedCommands.push({id:e,callback:t})},getPendingCommand:function(e){return n.detect(this.observedCommands,function(t){return t.id==e.cmdId})},removePendingCommand:function(e){var t=n.indexOf(this.observedCommands,e);this.observedCommands.splice(t,1)},register:function(e){this.denormalizers.push(e)}});t.CQRS.eventHandler=new u,t.Model=t.Model.extend({modelName:null,bindCQRS:function(e){e&&(this.modelName=e);if(!this.modelName)return;var n=this.id||this.cid;t.CQRS.eventHandler.bind(this.modelName+":"+n,this.apply,this),this.isCQRSBound=!0},unbindCQRS:function(e){e&&(this.modelName=e);if(!this.modelName)return;var n=this.id||this.cid;t.CQRS.eventHandler.unbind(this.modelName+":"+n,this.apply,this),this.isCQRSBound=!1},apply:function(e,t){t.apply(this,[e,this])}});var a=t.sync;t.CQRS.sync=function(e,t,n){var r=l[e];if(r!=="GET")return n.success();a(e,t,n)};var f=function(e,t){var n=t.split("."),r=0,i=e;while(n[r])i=i&&i[n[r]],r++;return i},l={create:"POST",update:"PUT","delete":"DELETE",read:"GET"}}).call(this) \ No newline at end of file diff --git a/backboneCQRS-0.5.5.js b/backboneCQRS-0.5.6.js similarity index 99% rename from backboneCQRS-0.5.5.js rename to backboneCQRS-0.5.6.js index eb515aa..7864a2f 100644 --- a/backboneCQRS-0.5.5.js +++ b/backboneCQRS-0.5.6.js @@ -368,7 +368,7 @@ // __only change is here__ only allow get! if (type !== 'GET') { - return options.success(); + return options.success(model, null, options); } else { origSync(method, model, options); } diff --git a/backboneCQRS-0.5.6.min.js b/backboneCQRS-0.5.6.min.js new file mode 100644 index 0000000..05c5bf5 --- /dev/null +++ b/backboneCQRS-0.5.6.min.js @@ -0,0 +1,5 @@ +// Backbone.CQRS.js +// (c) 2012 Jan Mühlemann +// Backbone.CQRS may be freely distributed under the MIT license. + +(function(){var e=this,t=e.Backbone;t.CQRS={};var n=e._,r=e.jQuery||e.Zepto,i=r.noop;t.CQRS.Message=t.Model.extend({url:i,fetch:i,save:i,destroy:i});var s=t.CQRS.Message.extend({});t.CQRS.Command=t.CQRS.Message.extend({emit:function(e){e&&this.observe(e),t.CQRS.hub.emit(t.CQRS.hub.commandsChannel,this.parse(this.toJSON()))},parse:function(e){return e},observe:function(e){t.CQRS.eventHandler.observe(this.id,e)}});var o=t.CQRS.hub={commandsChannel:"commands",defaults:{commandsChannel:"commands",eventsChannel:"events",eventNameAttr:"name",eventModelIdAttr:"payload.id",eventResponseToCommandId:"commandId"},init:function(e){var t=this;this.initialized||(this.initialized=!0,e=n.extend(this.defaults,e),e.parseEvent&&(this.parseEvent=e.parseEvent),e.getCommandId&&(this.getCommandId=e.getCommandId),this.commandsChannel=e.commandsChannel,this.on(e.eventsChannel,function(n){var r=new s;r.set(this.parseEvent(n));var i=r.toJSON();r.name=f(i,e.eventNameAttr),r.id=f(i,e.eventModelIdAttr),r.cmdId=t.getCommandId(i,e.eventResponseToCommandId),this.emit("dispatchEvent",r)}))},parseEvent:function(e){var t=e;return typeof t=="string"&&(t=JSON.parse(t)),t},getCommandId:function(e,t){return f(e,t)}};n.extend(o,t.Events),o.on=o.bind,o.emit=o.trigger,t.CQRS.EventDenormalizer=function(e){e=e||{},e.forEvent&&(this.forEvent=e.forEvent),e.forModel&&(this.forModel=e.forModel),e.payloadValue&&(this.payloadValue=e.payloadValue),e.modelIdAttr&&(this.modelIdAttr=e.modelIdAttr),e.onHandle&&(this.onHandle=e.onHandle),this.methode=e.methode||"update",this.model=e.model,this.collection=e.collection,this.forEvent&&this.forModel&&this.register.apply(this),this.initialize.apply(this,arguments)},n.extend(t.CQRS.EventDenormalizer.prototype,t.Events,{defaultPayloadValue:"payload",initialize:i,handle:function(e){var t=this.modelIdAttr?f(e.toJSON(),this.modelIdAttr):e.id;if(this.methode!=="create")t&&this.trigger("change:"+t,this.parse(e),this.apply(this.methode));else{var n=typeof this.collection=="function"?this.collection(e):this.collection;if(!n)return;var r=this.parse(e);n.add(r),this.onHandle&&this.onHandle(r,n.get(t))}},apply:function(e){var t=this;return function(n,r){e==="delete"?(r.isCQRSBound&&r.unbindCQRS(),r.destroy(),t.onHandle&&t.onHandle(n,r)):(r.set(n),t.onHandle&&t.onHandle(n,r))}},parse:function(e){return this.payloadValue||this.defaultPayloadValue?(diveTo=this.payloadValue||this.defaultPayloadValue,f(e.toJSON(),diveTo)):e.toJSON()},register:function(e,n){this.forEvent=e||this.forEvent,this.forModel=n||this.forModel,t.CQRS.eventHandler.register(this)}}),t.CQRS.EventDenormalizer.extend=t.Model.extend;var u=t.CQRS.EventDenormalizer.extend({initialize:function(){this.denormalizers=[],this.observedCommands=[],t.CQRS.hub.on("dispatchEvent",function(e){this.handle(e)},this)},getDenormalizer:function(e,t){return e?n(this.denormalizers).filter(function(t){return t.forEvent==e}):t?n(this.denormalizers).filter(function(e){return e.forModel==t}):null},handle:function(e){var t=this.getDenormalizer(e.name);n(t).each(function(t){t.handle(e)});var r=this.getPendingCommand(e);r&&(r.callback(e),this.removePendingCommand(r))},bind:function(e,t,r){if(e.indexOf(":")<0)return!1;var i=e.substring(0,e.indexOf(":")),s="change:"+e.substring(e.indexOf(":")+1,e.length),o=this.getDenormalizer(null,i);n(o).each(function(e){e.bind(s,t,r)})},unbind:function(e,t){if(e.indexOf(":")<0)return!1;var r=e.split(":"),i=r[0],s="change:"+r[1],o=this.getDenormalizer(null,i);n(o).each(function(e){e.unbind(s,t)})},observe:function(e,t){this.observedCommands.push({id:e,callback:t})},getPendingCommand:function(e){return n.detect(this.observedCommands,function(t){return t.id==e.cmdId})},removePendingCommand:function(e){var t=n.indexOf(this.observedCommands,e);this.observedCommands.splice(t,1)},register:function(e){this.denormalizers.push(e)}});t.CQRS.eventHandler=new u,t.Model=t.Model.extend({modelName:null,bindCQRS:function(e){e&&(this.modelName=e);if(!this.modelName)return;var n=this.id||this.cid;t.CQRS.eventHandler.bind(this.modelName+":"+n,this.apply,this),this.isCQRSBound=!0},unbindCQRS:function(e){e&&(this.modelName=e);if(!this.modelName)return;var n=this.id||this.cid;t.CQRS.eventHandler.unbind(this.modelName+":"+n,this.apply,this),this.isCQRSBound=!1},apply:function(e,t){t.apply(this,[e,this])}});var a=t.sync;t.CQRS.sync=function(e,t,n){var r=l[e];if(r!=="GET")return n.success(t,null,n);a(e,t,n)};var f=function(e,t){var n=t.split("."),r=0,i=e;while(n[r])i=i&&i[n[r]],r++;return i},l={create:"POST",update:"PUT","delete":"DELETE",read:"GET"}}).call(this) \ No newline at end of file diff --git a/package.json b/package.json index e1bf2d2..6e34c29 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ } , "dependencies": { } , "devDependencies": { - "smoosh": "0.2.x" + "smoosh": ">=0.2.x" , "jake": ">=0.0.1" } , "scripts": {