diff --git a/bower.json b/bower.json index 7045adb..a6db25a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "backbone.async", - "version": "1.1.0", + "version": "1.1.1", "homepage": "https://github.com/emaphp/backbone.async", "authors": [ "Emmanuel Antico " diff --git a/dist/backbone.async.js b/dist/backbone.async.js index 149367e..be662bc 100644 --- a/dist/backbone.async.js +++ b/dist/backbone.async.js @@ -1,5 +1,5 @@ /* - * Backbone.Async v1.1.0 + * Backbone.Async v1.1.1 * Copyright 2015 Emmanuel Antico * This library is distributed under the terms of the MIT license. */ @@ -94,7 +94,7 @@ //create namespace var Async = Backbone.Async = Backbone.Async || {}; - Async.VERSION = '1.1.0'; + Async.VERSION = '1.1.1'; //extend Model and Collection prototypes Async.Model = Backbone.Model.extend( diff --git a/dist/backbone.async.min.js b/dist/backbone.async.min.js index 972c3c7..05f4177 100644 --- a/dist/backbone.async.min.js +++ b/dist/backbone.async.min.js @@ -1 +1 @@ -!function(a,b){"function"==typeof define&&define.amd?define(["backbone","underscore"],function(c,d){return b(a,c,d)}):"undefined"!=typeof exports?module.exports=b(a,require("backbone"),require("underscore")):b(a,a.Backbone,a._)}(this,function(a,b,c){var d=function(a,b,c){return function(d,e,f){a&&a.apply(d,arguments);var g={response:e,options:f};g[c.collection?"collection":"model"]=d,b(g),"undefined"!=typeof f.silent&&f.silent||d.trigger("after:"+c.method,g,c.success)}},e=function(a,b,d,e){var f,g;return"save"===a?null===b||"object"==typeof b?(f=b,g=d):b&&((f={})[b]=d,g=e):g=b,g=g?c.extend({},g):{},{attrs:f,options:g}},f=function(a){return function(f,g){return f[g]=function(f,h,i){var j=this,k=e(g,f,h,i),l=k.options,m=k.attrs,n=l.success,o=l.error,p={method:g,collection:a===b.Collection.prototype};return new Promise(function(b,e){l.success=d(n,b,c.extend({success:!0},p)),l.error=d(o,e,c.extend({success:!1},p)),p.collection?("undefined"!=typeof l.silent&&l.silent||j.trigger("before:"+g,{collection:j,options:l}),a[g].call(j,l)):("undefined"!=typeof l.silent&&l.silent||j.trigger("before:"+g,"save"===g?{model:j,options:l,attrs:m}:{model:j,options:l}),a[g].apply(j,"save"===g?[m,l]:[l]))})},f}},g=function(a,b){return b.reduce(f(a.prototype),{})},h=b.Async=b.Async||{};h.VERSION="1.1.0",h.Model=b.Model.extend(g(b.Model,["fetch","save","destroy"])),h.Collection=b.Collection.extend(g(b.Collection,["fetch"]));var i=h.Storage=function(a){this.isLoaded=!1,a&&(a.Collection&&(this.Collection=a.Collection),a.Model?this.Model=a.Model:a.Collection&&a.Collection.model&&(this.Model=a.Collection.model)),i.prototype.initialize.apply(this,arguments)};return c.extend(i.prototype,b.Events,{initialize:function(){},fetch:function(a){if(this.isLoaded)return Promise.resolve({collection:this.collection,options:a});if(!this.Collection)throw new Error("No Collection class defined");a=a||{};var b=this,c="undefined"==typeof a.silent||!a.silent;return new Promise(function(d,e){b.collection||(b.collection=new b.Collection),c&&b.trigger("before:fetch",{collection:b.collection,options:a}),b.collection.fetch(a).then(function(a){c&&b.trigger("after:fetch",a,!0),b.isLoaded=!0,d(a)})["catch"](function(a){c&&b.trigger("after:fetch",a,!1),e(a)})})},get:function(a,b){if(this.collection){var c=this.collection.get(a);if(c)return Promise.resolve({model:c,options:b})}if(!this.Model)throw new Error("No Model class defined");if(!this.Collection)throw new Error("No Collection class defined");b=b||{};var d=this,e="undefined"==typeof b.silent||!b.silent;return new Promise(function(c,f){var g=new d.Model;g.set(d.Model.idAttribute||"id",a),e&&d.trigger("before:get",{model:g,options:b}),g.fetch(b).then(function(a){e&&d.trigger("after:get",a,!0),d.collection||(d.collection=new d.Collection),d.collection.push(g),d.listenTo(g,"after:destroy",function(a,b){b&&d.collection.remove(a.model,{silent:!0})}),c(a)})["catch"](function(a){e&&d.trigger("after:get",a,!1),f(a)})})},store:function(a){if(!this.Collection)throw new Error("No Collection class defined");this.collection||(this.collection=new this.Collection),this.collection.push(a),this.listenTo(a,"after:destroy",function(a,b){b&&this.collection.remove(a.model,{silent:!0})})}}),i.extend=b.Model.extend,h}); \ No newline at end of file +!function(a,b){"function"==typeof define&&define.amd?define(["backbone","underscore"],function(c,d){return b(a,c,d)}):"undefined"!=typeof exports?module.exports=b(a,require("backbone"),require("underscore")):b(a,a.Backbone,a._)}(this,function(a,b,c){var d=function(a,b,c){return function(d,e,f){a&&a.apply(d,arguments);var g={response:e,options:f};g[c.collection?"collection":"model"]=d,b(g),"undefined"!=typeof f.silent&&f.silent||d.trigger("after:"+c.method,g,c.success)}},e=function(a,b,d,e){var f,g;return"save"===a?null===b||"object"==typeof b?(f=b,g=d):b&&((f={})[b]=d,g=e):g=b,g=g?c.extend({},g):{},{attrs:f,options:g}},f=function(a){return function(f,g){return f[g]=function(f,h,i){var j=this,k=e(g,f,h,i),l=k.options,m=k.attrs,n=l.success,o=l.error,p={method:g,collection:a===b.Collection.prototype};return new Promise(function(b,e){l.success=d(n,b,c.extend({success:!0},p)),l.error=d(o,e,c.extend({success:!1},p)),p.collection?("undefined"!=typeof l.silent&&l.silent||j.trigger("before:"+g,{collection:j,options:l}),a[g].call(j,l)):("undefined"!=typeof l.silent&&l.silent||j.trigger("before:"+g,"save"===g?{model:j,options:l,attrs:m}:{model:j,options:l}),a[g].apply(j,"save"===g?[m,l]:[l]))})},f}},g=function(a,b){return b.reduce(f(a.prototype),{})},h=b.Async=b.Async||{};h.VERSION="1.1.1",h.Model=b.Model.extend(g(b.Model,["fetch","save","destroy"])),h.Collection=b.Collection.extend(g(b.Collection,["fetch"]));var i=h.Storage=function(a){this.isLoaded=!1,a&&(a.Collection&&(this.Collection=a.Collection),a.Model?this.Model=a.Model:a.Collection&&a.Collection.model&&(this.Model=a.Collection.model)),i.prototype.initialize.apply(this,arguments)};return c.extend(i.prototype,b.Events,{initialize:function(){},fetch:function(a){if(this.isLoaded)return Promise.resolve({collection:this.collection,options:a});if(!this.Collection)throw new Error("No Collection class defined");a=a||{};var b=this,c="undefined"==typeof a.silent||!a.silent;return new Promise(function(d,e){b.collection||(b.collection=new b.Collection),c&&b.trigger("before:fetch",{collection:b.collection,options:a}),b.collection.fetch(a).then(function(a){c&&b.trigger("after:fetch",a,!0),b.isLoaded=!0,d(a)})["catch"](function(a){c&&b.trigger("after:fetch",a,!1),e(a)})})},get:function(a,b){if(this.collection){var c=this.collection.get(a);if(c)return Promise.resolve({model:c,options:b})}if(!this.Model)throw new Error("No Model class defined");if(!this.Collection)throw new Error("No Collection class defined");b=b||{};var d=this,e="undefined"==typeof b.silent||!b.silent;return new Promise(function(c,f){var g=new d.Model;g.set(d.Model.idAttribute||"id",a),e&&d.trigger("before:get",{model:g,options:b}),g.fetch(b).then(function(a){e&&d.trigger("after:get",a,!0),d.collection||(d.collection=new d.Collection),d.collection.push(g),d.listenTo(g,"after:destroy",function(a,b){b&&d.collection.remove(a.model,{silent:!0})}),c(a)})["catch"](function(a){e&&d.trigger("after:get",a,!1),f(a)})})},store:function(a){if(!this.Collection)throw new Error("No Collection class defined");this.collection||(this.collection=new this.Collection),this.collection.push(a),this.listenTo(a,"after:destroy",function(a,b){b&&this.collection.remove(a.model,{silent:!0})})}}),i.extend=b.Model.extend,h}); \ No newline at end of file diff --git a/package.json b/package.json index 18c3748..3516907 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backbone.async", - "version": "1.1.0", + "version": "1.1.1", "description": "Backbone Models meet Promises", "author": "Emmanuel Antico ", "license": "MIT", @@ -25,7 +25,6 @@ "promise-polyfill": "^2.0.0" }, "scripts": { - "postinstall": "mkdir -p test/lib/ && wget http://sinonjs.org/releases/sinon-1.13.0.js -O test/lib/sinon-1.13.0.js && grunt vendor", - "test": "grunt test && mocha-phantomjs test/test.html" + "test": "echo \"Error: no test specified\" && exit 1" } }