forked from vidigami/backbone-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackbone-http.min.js
8 lines (8 loc) · 4.07 KB
/
backbone-http.min.js
1
2
3
4
5
6
7
8
/*
backbone-http.js 0.7.2
Copyright (c) 2013-2015 Vidigami
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Source: https://github.com/vidigami/backbone-http
Dependencies: Backbone.js, Underscore.js, and BackboneORM.
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("backbone-orm")):"function"==typeof define&&define.amd?define(["backbone-orm"],t):"object"==typeof exports?exports.BackboneHTTP=t(require("backbone-orm")):e.BackboneHTTP=t(e.BackboneORM)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){var n,o,u,i,s,c,l,a,p;l=u=r(1),i=l._,n=l.Backbone,e.exports=o=r(2),c={configure:r(3),sync:r(4),_:i,Backbone:n},i.extend(o,c),o.modules={"backbone-orm":u},a=u.modules;for(s in a)p=a[s],o.modules[s]=p},function(t,r,n){t.exports=e},function(e,t,r){e.exports={}},function(e,t,r){e.exports=r(1).configure},function(e,t,r){var n,o,u,i,s,c,l,a,p,f,y,d;d=o=r(1),f=d._,n=d.Backbone,p=d.Utils,c=d.JSONUtils,l=d.Schema,a=o.modules.url,y=n.sync,i=r(5),u={embed:"maybe",json:"maybe",unique:"maybe",manual_ids:!1,dynamic:!1,self_reference:"maybe"},s=function(){function e(e,t){if(this.model_type=e,null==t&&(t={}),this.model_type.model_name=p.findOrGenerateModelName(this.model_type),!(this.url=f.result(new this.model_type,"url")))throw new Error("Missing url for model: "+this.model_type);this.schema=new l(this.model_type,{id:{type:"_raw"}}),this.beforeSend=t.beforeSend,this.event_emitter=f.extend({},n.Events)}return e.prototype.initialize=function(e){return this.is_initialized?void 0:(this.is_initialized=!0,this.schema.initialize())},e.prototype.resetSchema=function(e,t){return this.http("delete",null,{},t)},e.prototype.cursor=function(e){return null==e&&(e={}),new i(e,{model_type:this.model_type,sync:this})},e.prototype.destroy=function(e,t){var r;return 1===arguments.length&&(r=[{},e],e=r[0],t=r[1]),this.http("delete",null,{query:e},t)},e.prototype.http=function(e,t,r,n){var o,u;return o=t?f.result(t,"url"):this.url,r.query&&f.size(r.query)&&(u=a.parse(o,!0),f.extend(u.query,c.querify(r.query)),o=a.format(u)),y(e,t||this.event_emitter,f.extend({url:o,beforeSend:this.beforeSend},r,{success:function(e){return n(null,c.parse(e))},error:function(t){return n(f.extend(new Error("Ajax failed with status "+t.status+" for "+e),{status:t.status,json:t.responseJSON,text:t.responseText}))}}))},e}(),e.exports=function(t,r){var n,u,i;return p.isCollection(new t)?(n=p.configureCollectionModelType(t,e.exports,r),t.prototype.sync=n.prototype.sync):(u=new s(t,r),t.prototype.sync=i=function(t,r,n){var o;if(null==n&&(n={}),u.initialize(),"createSync"===t)return e.exports.apply(null,Array.prototype.slice.call(arguments,1));if("sync"===t)return u;if("schema"===t)return u.schema;if("isRemote"===t)return!0;if(f.contains(["create","update","patch","delete","read"],t)){if(!(o=n.url||f.result(r,"url")))throw new Error("Missing url for model");return"read"===t&&(n=f.extend({$one:!r.models},n)),void u.http(t,r,f.omit(n,"error","success"),function(e){return function(e,t){return e?n.error(e):n.success(t)}}(this))}return u[t]?u[t].apply(u,Array.prototype.slice.call(arguments,1)):void 0},p.configureModelType(t),o.model_cache.configureSync(t,i))},e.exports.capabilities=function(e){return u}},function(e,t,r){var n,o,u,i,s=function(e,t){function r(){this.constructor=e}for(var n in t)c.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},c={}.hasOwnProperty;i=r(1),u=i._,n=i.Cursor,e.exports=o=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return s(t,e),t.prototype.toJSON=function(e){var t;return this.hasCursorQuery("$zero")?e(null,this.hasCursorQuery("$one")?null:[]):this.sync.http("read",null,{query:t=u.extend({},this._find,this._cursor)},function(r){return function(n,o){return t.$one&&n&&404===n.status?e(null,null):n?e(n):e(null,r.hasCursorQuery("$count")||r.hasCursorQuery("$exists")?o.result:o)}}(this))},t}(n)}])});