fs.collections
Advanced tools
Comparing version 2.1.1 to 3.0.0
@@ -11,2 +11,3 @@ var browserify = require('browserify') | ||
var ngannotate = require('browserify-ngannotate') | ||
var derequire = require('gulp-derequire') | ||
@@ -21,2 +22,3 @@ var files = [ | ||
entries: files, | ||
basedir: __dirname, | ||
debug: true, | ||
@@ -26,7 +28,6 @@ // defining transforms here will avoid crashing your stream | ||
}) | ||
.external('angular') | ||
.external('underscore') | ||
return b.bundle() | ||
.pipe(source('index.js')) | ||
.pipe(derequire()) | ||
.pipe(buffer()) | ||
@@ -49,7 +50,6 @@ .pipe(sourcemaps.init({loadMaps: true})) | ||
}) | ||
.external('angular') | ||
.external('underscore') | ||
return b.bundle() | ||
.pipe(source('index.min.js')) | ||
.pipe(derequire()) | ||
.pipe(buffer()) | ||
@@ -56,0 +56,0 @@ .pipe(sourcemaps.init({loadMaps: true})) |
128
index.js
@@ -1,2 +0,2 @@ | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
@@ -8,16 +8,10 @@ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* eslint-disable no-return-assign */ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
exports.default = BaseCollection; | ||
/* eslint-disable no-return-assign */ | ||
/* global _ */ | ||
var _underscore = require('underscore'); | ||
var _underscore2 = _interopRequireDefault(_underscore); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function BaseCollection($http, BaseModel) { | ||
exports.default = ['$http', 'BaseModel', function ($http, BaseModel) { | ||
var BaseCollection = function () { | ||
@@ -72,11 +66,11 @@ function BaseCollection(models, opts) { | ||
method: 'GET', | ||
url: (0, _underscore2.default)(this).result('url') | ||
url: _(this).result('url') | ||
}; | ||
options = _underscore2.default.extend(defaults, options); | ||
options = _.extend(defaults, options); | ||
if (options.params) { | ||
options.params = _underscore2.default.extend({}, options.params); | ||
options.params = _.extend({}, options.params); | ||
} | ||
if (options.data) { | ||
options.data = _underscore2.default.extend({}, options.data); | ||
options.data = _.extend({}, options.data); | ||
} | ||
@@ -109,3 +103,3 @@ | ||
value: function get(id) { | ||
return (0, _underscore2.default)(this.models).findWhere({ id: id }); | ||
return _(this.models).findWhere({ id: id }); | ||
} | ||
@@ -117,3 +111,3 @@ }, { | ||
var isSingular = !(0, _underscore2.default)(models).isArray(); | ||
var isSingular = !_(models).isArray(); | ||
if (isSingular) { | ||
@@ -124,3 +118,3 @@ models = [models]; | ||
(0, _underscore2.default)(models).forEach(function (model) { | ||
_(models).forEach(function (model) { | ||
var index = _this2.indexOf(model); | ||
@@ -146,3 +140,3 @@ if (index === -1) { | ||
options = _underscore2.default.extend({ sort: true }, options); | ||
options = _.extend({ sort: true }, options); | ||
@@ -156,3 +150,3 @@ if (options.parse) { | ||
var isSingular = !(0, _underscore2.default)(models).isArray(); | ||
var isSingular = !_(models).isArray(); | ||
models = isSingular ? [models] : models.slice(); | ||
@@ -199,3 +193,3 @@ var added = []; | ||
value: function toJSON() { | ||
return _underscore2.default.map(this.models, function (model) { | ||
return _.map(this.models, function (model) { | ||
return model.toJSON(); | ||
@@ -222,3 +216,3 @@ }); | ||
var model = void 0; | ||
options = _underscore2.default.extend({ collection: this }, options); | ||
options = _.extend({ collection: this }, options); | ||
if (attrs instanceof this.model || attrs instanceof BaseCollection) { | ||
@@ -237,3 +231,3 @@ model = attrs; | ||
value: function pluck(attr) { | ||
return _underscore2.default.invoke(this.models, 'get', attr); | ||
return _.invoke(this.models, 'get', attr); | ||
} | ||
@@ -279,3 +273,3 @@ }, { | ||
// Mix in each Underscore method as a proxy to `Collection#models`. | ||
_underscore2.default.each(methods, function (method) { | ||
_.each(methods, function (method) { | ||
return BaseCollection.prototype[method] = function () { | ||
@@ -287,3 +281,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args.unshift(this.models); | ||
return _underscore2.default[method].apply(_underscore2.default, args); | ||
return _[method].apply(_, args); | ||
}; | ||
@@ -296,8 +290,8 @@ }); | ||
// Use attributes instead of properties. | ||
_underscore2.default.each(attributeMethods, function (method) { | ||
_.each(attributeMethods, function (method) { | ||
return BaseCollection.prototype[method] = function (value, context) { | ||
var iterator = _underscore2.default.isFunction(value) ? value : function (model) { | ||
var iterator = _.isFunction(value) ? value : function (model) { | ||
return model.get(value); | ||
}; | ||
return _underscore2.default[method](this.models, iterator, context); | ||
return _[method](this.models, iterator, context); | ||
}; | ||
@@ -307,24 +301,21 @@ }); | ||
return BaseCollection; | ||
} | ||
}]; | ||
},{"underscore":"underscore"}],2:[function(require,module,exports){ | ||
},{}],2:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var _collection = require('./collection.js'); | ||
var _collection = _dereq_('./collection.js'); | ||
var _collection2 = _interopRequireDefault(_collection); | ||
var _model = require('./model.js'); | ||
var _model = _dereq_('./model.js'); | ||
var _model2 = _interopRequireDefault(_model); | ||
var _angular = require('angular'); | ||
var _angular2 = _interopRequireDefault(_angular); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
_angular2.default.module('fs.collections', []).factory('BaseCollection', _collection2.default).factory('BaseModel', _model2.default); | ||
/* global angular */ | ||
angular.module('fs.collections', []).factory('BaseCollection', _collection2.default).factory('BaseModel', _model2.default); | ||
},{"./collection.js":1,"./model.js":3,"angular":"angular"}],3:[function(require,module,exports){ | ||
},{"./collection.js":1,"./model.js":3}],3:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
@@ -338,16 +329,9 @@ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* eslint-disable no-return-assign */ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
exports.default = BaseModel; | ||
var _underscore = require('underscore'); | ||
var _underscore2 = _interopRequireDefault(_underscore); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function BaseModel($http, $rootScope) { | ||
/* eslint-disable no-return-assign */ | ||
/* global _ */ | ||
exports.default = ['$http', '$rootScope', function ($http, $rootScope) { | ||
var BaseModel = function () { | ||
@@ -366,3 +350,3 @@ _createClass(BaseModel, [{ | ||
value: function _hasIdAttribute(attrs) { | ||
return (0, _underscore2.default)(Object.keys(attrs)).contains(this.idAttribute); | ||
return _(Object.keys(attrs)).contains(this.idAttribute); | ||
} | ||
@@ -387,3 +371,3 @@ }]); | ||
this._eventBus.$on('$destroy', function () { | ||
return (0, _underscore2.default)(_this._eventBus.destuctors).each(function (callbacks, event) { | ||
return _(_this._eventBus.destuctors).each(function (callbacks, event) { | ||
return callbacks.forEach(function (obj) { | ||
@@ -409,4 +393,4 @@ return obj.unwatch(); | ||
this.attributes = {}; | ||
attrs = _underscore2.default.extend({}, attrs); | ||
attrs = _underscore2.default.defaults(attrs, _underscore2.default.result(this, 'defaults')); | ||
attrs = _.extend({}, attrs); | ||
attrs = _.defaults(attrs, _.result(this, 'defaults')); | ||
this.set(attrs); | ||
@@ -515,3 +499,3 @@ } | ||
(0, _underscore2.default)(attrs).each(function (aVal, aKey) { | ||
_(attrs).each(function (aVal, aKey) { | ||
if (_this3.attributes[aKey] !== aVal) { | ||
@@ -524,3 +508,3 @@ changed[aKey] = aVal; | ||
this.trigger('change', this, changed); | ||
(0, _underscore2.default)(changed).each(function (val, key) { | ||
_(changed).each(function (val, key) { | ||
return _this3.trigger('change:' + key, _this3, val); | ||
@@ -543,3 +527,3 @@ }); | ||
value: function url() { | ||
var base = _underscore2.default.result(this, 'urlRoot') || _underscore2.default.result(this.collection, 'url'); | ||
var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url'); | ||
if (this.isNew()) { | ||
@@ -555,3 +539,3 @@ return base; | ||
value: function toJSON() { | ||
return _underscore2.default.clone(this.attributes); | ||
return _.clone(this.attributes); | ||
} | ||
@@ -563,9 +547,9 @@ }, { | ||
var opts = _underscore2.default.extend({}, options); | ||
var opts = _.extend({}, options); | ||
(0, _underscore2.default)(opts).defaults({ | ||
_(opts).defaults({ | ||
method: 'GET', | ||
url: _underscore2.default.result(this, 'url') | ||
url: _.result(this, 'url') | ||
}); | ||
return $http(opts).then((0, _underscore2.default)(this.parse).bind(this)).then((0, _underscore2.default)(this.set).bind(this)); | ||
return $http(opts).then(_(this.parse).bind(this)).then(_(this.set).bind(this)); | ||
} | ||
@@ -577,10 +561,10 @@ }, { | ||
var opts = _underscore2.default.extend({}, options); | ||
var opts = _.extend({}, options); | ||
(0, _underscore2.default)(opts).defaults({ | ||
_(opts).defaults({ | ||
method: this.isNew() ? 'POST' : 'PUT', | ||
url: _underscore2.default.result(this, 'url'), | ||
url: _.result(this, 'url'), | ||
data: this.toJSON() | ||
}); | ||
return $http(opts).then((0, _underscore2.default)(this.parse).bind(this)).then((0, _underscore2.default)(this.set).bind(this)); | ||
return $http(opts).then(_(this.parse).bind(this)).then(_(this.set).bind(this)); | ||
} | ||
@@ -605,7 +589,7 @@ }, { | ||
} else { | ||
(0, _underscore2.default)(opts).defaults({ | ||
_(opts).defaults({ | ||
method: 'DELETE', | ||
url: this.url('delete') | ||
}); | ||
return $http(opts).then((0, _underscore2.default)(this.parse).bind(this)).then(destroy); | ||
return $http(opts).then(_(this.parse).bind(this)).then(destroy); | ||
} | ||
@@ -625,3 +609,3 @@ } | ||
// Mix in each Underscore method as a proxy to `Model#attributes`. | ||
_underscore2.default.each(modelMethods, function (method) { | ||
_.each(modelMethods, function (method) { | ||
return BaseModel.prototype[method] = function () { | ||
@@ -633,3 +617,3 @@ for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args.unshift(this.attributes); | ||
return _underscore2.default[method].apply(_underscore2.default, args); | ||
return _[method].apply(_, args); | ||
}; | ||
@@ -639,7 +623,7 @@ }); | ||
return BaseModel; | ||
} | ||
}]; | ||
},{"underscore":"underscore"}]},{},[2]) | ||
},{}]},{},[2]) | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function t(e,r,n){function u(o,s){if(!r[o]){if(!e[o]){var a="function"==typeof require&&require;if(!s&&a)return a(o,!0);if(i)return i(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var f=r[o]={exports:{}};e[o][0].call(f.exports,function(t){var r=e[o][1][t];return u(r?r:t)},f,f.exports,t,e,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)u(n[o]);return u}({1:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){var r=function(){function r(t,n){u(this,r),this.model=e,this.currentlyFetching=!1,this.opts=n,this.opts&&(this.opts.model&&(this.model=this.opts.model),this.opts.url&&(this.url=this.opts.url),this.opts.sort&&(this.sort=this.opts.sort),this.opts.comparator&&(this.comparator=this.opts.comparator),this.opts.parse&&"function"==typeof this.opts.parse&&(this.parse=this.opts.parse,delete this.opts.parse)),this.models=[],this.length=0,this.add(t,this.opts)}return o(r,[{key:"url",value:function(){}},{key:"parse",value:function(t){return t.data}},{key:"fetch",value:function(e){var r=this,n={merge:!0,parse:!0,method:"GET",url:(0,a["default"])(this).result("url")};e=a["default"].extend(n,e),e.params&&(e.params=a["default"].extend({},e.params)),e.data&&(e.data=a["default"].extend({},e.data)),this.currentlyFetching=!0;var u=t(e).then(function(t){return e.reset&&r.reset(),r.add(t,e),r});return u["finally"](function(){return r.currentlyFetching=!1}),u}},{key:"eq",value:function(t){if(this.models)return this.models[t]}},{key:"get",value:function(t){return(0,a["default"])(this.models).findWhere({id:t})}},{key:"remove",value:function(t){var e=this,r=!(0,a["default"])(t).isArray();r&&(t=[t]);var n=[];return(0,a["default"])(t).forEach(function(t){var r=e.indexOf(t);if(r!==-1)return n.push(t),e.models.splice(r,1),e.length--}),r?n[0]:n}},{key:"add",value:function(t,e){var r=this;if(e=a["default"].extend({sort:!0},e),e.parse&&(t=this.parse(t)),t){var n=!(0,a["default"])(t).isArray();t=n?[t]:t.slice();var u=[],i="undefined"==typeof e.at?this.length:e.at;return t.forEach(function(t){t=r._prepareModel(t,e);var n=r.get(t.id);return null==n?(u.push(t),r.length++,r.models.splice(i,0,t),i++):e.merge?n.set(t.attributes,e):void 0}),e.sort&&this.sort(),n?u[0]:u}}},{key:"create",value:function(t,e){var r=this.add(t,e);if(r)return r.save()}},{key:"clone",value:function(){return new this.constructor(this.toJSON(),this.opts)}},{key:"toJSON",value:function(){return a["default"].map(this.models,function(t){return t.toJSON()})}},{key:"reset",value:function(){return this.models=[],this.length=0,this}},{key:"sort",value:function(){if(this.comparator)return this.models.sort(this.comparator)}},{key:"_prepareModel",value:function(t,e){var n=void 0;return e=a["default"].extend({collection:this},e),t instanceof this.model||t instanceof r?(n=t,n.collection=this):n=new this.model(t,e),n}},{key:"pluck",value:function(t){return a["default"].invoke(this.models,"get",t)}},{key:"where",value:function(t,e){if(!t)return e?void 0:[];var r="filter";return e&&(r="find"),this[r](function(e){for(var r in t)if(t[r]!==e.get(r))return!1;return!0})}},{key:"findWhere",value:function(t){return this.where(t,!0)}}]),r}(),n=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain"];a["default"].each(n,function(t){return r.prototype[t]=function(){for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];return r.unshift(this.models),a["default"][t].apply(a["default"],r)}});var i=["groupBy","countBy","sortBy"];return a["default"].each(i,function(t){return r.prototype[t]=function(e,r){var n=a["default"].isFunction(e)?e:function(t){return t.get(e)};return a["default"][t](this.models,n,r)}}),r}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();r["default"]=i;var s=t("underscore"),a=n(s)},{underscore:"underscore"}],2:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}var u=t("./collection.js"),i=n(u),o=t("./model.js"),s=n(o),a=t("angular"),l=n(a);l["default"].module("fs.collections",[]).factory("BaseCollection",i["default"]).factory("BaseModel",s["default"])},{"./collection.js":1,"./model.js":3,angular:"angular"}],3:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){var r=function(){function r(){var t=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];u(this,r),this.urlRoot="",this.idAttribute="id",i.parse&&(n=this.parse(n)),this._eventBus=e.$new(),this._eventBus.destuctors={},this._eventBus.$on("$destroy",function(){return(0,l["default"])(t._eventBus.destuctors).each(function(t,e){return t.forEach(function(t){return t.unwatch()})})}),i.collection&&(this.collection=i.collection),i.urlRoot&&(this.urlRoot=i.urlRoot),i.idAttribute&&(this.idAttribute=i.idAttribute),i.defaults&&(this.defaults=i.defaults),this.attributes={},n=l["default"].extend({},n),n=l["default"].defaults(n,l["default"].result(this,"defaults")),this.set(n)}return s(r,[{key:"parse",value:function(t){return t.status&&t.headers?t.data:t}},{key:"_hasIdAttribute",value:function(t){return(0,l["default"])(Object.keys(t)).contains(this.idAttribute)}}]),s(r,[{key:"trigger",value:function(){for(var t=arguments.length,e=Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._eventBus.$broadcast.apply(this._eventBus,e)}},{key:"on",value:function(t,e){this._eventBus.destuctors[t]||(this._eventBus.destuctors[t]=[]);var r=this._eventBus.destuctors[t],n=function(t,r){for(var n=arguments.length,u=Array(n>2?n-2:0),i=2;i<n;i++)u[i-2]=arguments[i];return e.apply(this,[r].concat(u))};return r.push({unwatch:this._eventBus.$on(t,n),original:e})}},{key:"off",value:function(t,e){var r=this._eventBus.destuctors[t]||[],n=[];return n=e?r.filter(function(t){return t.original===e}):r,n.forEach(function(t){return t.unwatch()})}},{key:"once",value:function(t,e){var r=this,n=function u(){for(var n=arguments.length,i=Array(n),o=0;o<n;o++)i[o]=arguments[o];return r.off(t,u),e.apply(r,i)};return this.on(t,n)}},{key:"has",value:function(t){return null!=this.attributes[t]}},{key:"get",value:function(t){return this.attributes[t]}},{key:"set",value:function(t,e){var r=this,n=void 0;if(!t)return this;"object"===("undefined"==typeof t?"undefined":o(t))?n=t:(n={},n[t]=e);var u={};return this._hasIdAttribute(n)&&(this.id=n[this.idAttribute]),(0,l["default"])(n).each(function(t,e){return r.attributes[e]!==t&&(u[e]=t),r.attributes[e]=t}),this.trigger("change",this,u),(0,l["default"])(u).each(function(t,e){return r.trigger("change:"+e,r,t)}),this}},{key:"isNew",value:function(){return null==this.id}},{key:"url",value:function(){var t=l["default"].result(this,"urlRoot")||l["default"].result(this.collection,"url");if(this.isNew())return t;var e=encodeURIComponent(this.id);return t+("/"===t.charAt(t.length-1)?e:"/"+e)}},{key:"toJSON",value:function(){return l["default"].clone(this.attributes)}},{key:"fetch",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=l["default"].extend({},e);return(0,l["default"])(r).defaults({method:"GET",url:l["default"].result(this,"url")}),t(r).then((0,l["default"])(this.parse).bind(this)).then((0,l["default"])(this.set).bind(this))}},{key:"save",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=l["default"].extend({},e);return(0,l["default"])(r).defaults({method:this.isNew()?"POST":"PUT",url:l["default"].result(this,"url"),data:this.toJSON()}),t(r).then((0,l["default"])(this.parse).bind(this)).then((0,l["default"])(this.set).bind(this))}},{key:"destroy",value:function n(){var e=this,r=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.collection&&this.collection.remove(this);var n=function(){return e.trigger("destroy",e,e.collection,r),e._eventBus.$destroy()};return this.isNew()?n():((0,l["default"])(r).defaults({method:"DELETE",url:this.url("delete")}),t(r).then((0,l["default"])(this.parse).bind(this)).then(n))}}]),r}(),n=["keys","values","pairs","invert","pick","omit"];return l["default"].each(n,function(t){return r.prototype[t]=function(){for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];return r.unshift(this.attributes),l["default"][t].apply(l["default"],r)}}),r}Object.defineProperty(r,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();r["default"]=i;var a=t("underscore"),l=n(a)},{underscore:"underscore"}]},{},[2]); | ||
!function t(e,r,n){function i(u,s){if(!r[u]){if(!e[u]){var a="function"==typeof require&&require;if(!s&&a)return a(u,!0);if(o)return o(u,!0);var l=new Error("Cannot find module '"+u+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[u]={exports:{}};e[u][0].call(c.exports,function(t){var r=e[u][1][t];return i(r?r:t)},c,c.exports,t,e,r,n)}return r[u].exports}for(var o="function"==typeof require&&require,u=0;u<n.length;u++)i(n[u]);return i}({1:[function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();r.default=["$http","BaseModel",function(t,e){var r=function(){function r(t,i){n(this,r),this.model=e,this.currentlyFetching=!1,this.opts=i,this.opts&&(this.opts.model&&(this.model=this.opts.model),this.opts.url&&(this.url=this.opts.url),this.opts.sort&&(this.sort=this.opts.sort),this.opts.comparator&&(this.comparator=this.opts.comparator),this.opts.parse&&"function"==typeof this.opts.parse&&(this.parse=this.opts.parse,delete this.opts.parse)),this.models=[],this.length=0,this.add(t,this.opts)}return i(r,[{key:"url",value:function(){}},{key:"parse",value:function(t){return t.data}},{key:"fetch",value:function(e){var r=this,n={merge:!0,parse:!0,method:"GET",url:_(this).result("url")};e=_.extend(n,e),e.params&&(e.params=_.extend({},e.params)),e.data&&(e.data=_.extend({},e.data)),this.currentlyFetching=!0;var i=t(e).then(function(t){return e.reset&&r.reset(),r.add(t,e),r});return i.finally(function(){return r.currentlyFetching=!1}),i}},{key:"eq",value:function(t){if(this.models)return this.models[t]}},{key:"get",value:function(t){return _(this.models).findWhere({id:t})}},{key:"remove",value:function(t){var e=this,r=!_(t).isArray();r&&(t=[t]);var n=[];return _(t).forEach(function(t){var r=e.indexOf(t);if(r!==-1)return n.push(t),e.models.splice(r,1),e.length--}),r?n[0]:n}},{key:"add",value:function(t,e){var r=this;if(e=_.extend({sort:!0},e),e.parse&&(t=this.parse(t)),t){var n=!_(t).isArray();t=n?[t]:t.slice();var i=[],o="undefined"==typeof e.at?this.length:e.at;return t.forEach(function(t){t=r._prepareModel(t,e);var n=r.get(t.id);return null==n?(i.push(t),r.length++,r.models.splice(o,0,t),o++):e.merge?n.set(t.attributes,e):void 0}),e.sort&&this.sort(),n?i[0]:i}}},{key:"create",value:function(t,e){var r=this.add(t,e);if(r)return r.save()}},{key:"clone",value:function(){return new this.constructor(this.toJSON(),this.opts)}},{key:"toJSON",value:function(){return _.map(this.models,function(t){return t.toJSON()})}},{key:"reset",value:function(){return this.models=[],this.length=0,this}},{key:"sort",value:function(){if(this.comparator)return this.models.sort(this.comparator)}},{key:"_prepareModel",value:function(t,e){var n=void 0;return e=_.extend({collection:this},e),t instanceof this.model||t instanceof r?(n=t,n.collection=this):n=new this.model(t,e),n}},{key:"pluck",value:function(t){return _.invoke(this.models,"get",t)}},{key:"where",value:function(t,e){if(!t)return e?void 0:[];var r="filter";return e&&(r="find"),this[r](function(e){for(var r in t)if(t[r]!==e.get(r))return!1;return!0})}},{key:"findWhere",value:function(t){return this.where(t,!0)}}]),r}(),o=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain"];_.each(o,function(t){return r.prototype[t]=function(){for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];return r.unshift(this.models),_[t].apply(_,r)}});var u=["groupBy","countBy","sortBy"];return _.each(u,function(t){return r.prototype[t]=function(e,r){var n=_.isFunction(e)?e:function(t){return t.get(e)};return _[t](this.models,n,r)}}),r}]},{}],2:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var i=t("./collection.js"),o=n(i),u=t("./model.js"),s=n(u);angular.module("fs.collections",[]).factory("BaseCollection",o.default).factory("BaseModel",s.default)},{"./collection.js":1,"./model.js":3}],3:[function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},o=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();r.default=["$http","$rootScope",function(t,e){var r=function(){function r(){var t=this,i=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];n(this,r),this.urlRoot="",this.idAttribute="id",o.parse&&(i=this.parse(i)),this._eventBus=e.$new(),this._eventBus.destuctors={},this._eventBus.$on("$destroy",function(){return _(t._eventBus.destuctors).each(function(t,e){return t.forEach(function(t){return t.unwatch()})})}),o.collection&&(this.collection=o.collection),o.urlRoot&&(this.urlRoot=o.urlRoot),o.idAttribute&&(this.idAttribute=o.idAttribute),o.defaults&&(this.defaults=o.defaults),this.attributes={},i=_.extend({},i),i=_.defaults(i,_.result(this,"defaults")),this.set(i)}return o(r,[{key:"parse",value:function(t){return t.status&&t.headers?t.data:t}},{key:"_hasIdAttribute",value:function(t){return _(Object.keys(t)).contains(this.idAttribute)}}]),o(r,[{key:"trigger",value:function(){for(var t=arguments.length,e=Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._eventBus.$broadcast.apply(this._eventBus,e)}},{key:"on",value:function(t,e){this._eventBus.destuctors[t]||(this._eventBus.destuctors[t]=[]);var r=this._eventBus.destuctors[t],n=function(t,r){for(var n=arguments.length,i=Array(n>2?n-2:0),o=2;o<n;o++)i[o-2]=arguments[o];return e.apply(this,[r].concat(i))};return r.push({unwatch:this._eventBus.$on(t,n),original:e})}},{key:"off",value:function(t,e){var r=this._eventBus.destuctors[t]||[],n=[];return n=e?r.filter(function(t){return t.original===e}):r,n.forEach(function(t){return t.unwatch()})}},{key:"once",value:function(t,e){var r=this,n=function n(){for(var i=arguments.length,o=Array(i),u=0;u<i;u++)o[u]=arguments[u];return r.off(t,n),e.apply(r,o)};return this.on(t,n)}},{key:"has",value:function(t){return null!=this.attributes[t]}},{key:"get",value:function(t){return this.attributes[t]}},{key:"set",value:function(t,e){var r=this,n=void 0;if(!t)return this;"object"===("undefined"==typeof t?"undefined":i(t))?n=t:(n={},n[t]=e);var o={};return this._hasIdAttribute(n)&&(this.id=n[this.idAttribute]),_(n).each(function(t,e){return r.attributes[e]!==t&&(o[e]=t),r.attributes[e]=t}),this.trigger("change",this,o),_(o).each(function(t,e){return r.trigger("change:"+e,r,t)}),this}},{key:"isNew",value:function(){return null==this.id}},{key:"url",value:function(){var t=_.result(this,"urlRoot")||_.result(this.collection,"url");if(this.isNew())return t;var e=encodeURIComponent(this.id);return t+("/"===t.charAt(t.length-1)?e:"/"+e)}},{key:"toJSON",value:function(){return _.clone(this.attributes)}},{key:"fetch",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=_.extend({},e);return _(r).defaults({method:"GET",url:_.result(this,"url")}),t(r).then(_(this.parse).bind(this)).then(_(this.set).bind(this))}},{key:"save",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=_.extend({},e);return _(r).defaults({method:this.isNew()?"POST":"PUT",url:_.result(this,"url"),data:this.toJSON()}),t(r).then(_(this.parse).bind(this)).then(_(this.set).bind(this))}},{key:"destroy",value:function e(){var r=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.collection&&this.collection.remove(this);var e=function(){return r.trigger("destroy",r,r.collection,n),r._eventBus.$destroy()};return this.isNew()?e():(_(n).defaults({method:"DELETE",url:this.url("delete")}),t(n).then(_(this.parse).bind(this)).then(e))}}]),r}(),u=["keys","values","pairs","invert","pick","omit"];return _.each(u,function(t){return r.prototype[t]=function(){for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];return r.unshift(this.attributes),_[t].apply(_,r)}}),r}]},{}]},{},[2]); | ||
//# sourceMappingURL=index.min.js.map |
@@ -5,2 +5,4 @@ module.exports = function (config) { | ||
files: [ | ||
'node_modules/angular/angular.js', | ||
'node_modules/underscore/underscore.js', | ||
'src/index.js', | ||
@@ -7,0 +9,0 @@ 'tests/**/*.js', |
{ | ||
"name": "fs.collections", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"description": "Backbone style models and collections for AngularJS", | ||
@@ -51,3 +51,6 @@ "main": "index.js", | ||
"watchify": "^3.7.0" | ||
}, | ||
"dependencies": { | ||
"gulp-derequire": "^2.1.0" | ||
} | ||
} |
/* eslint-disable no-return-assign */ | ||
import _ from 'underscore' | ||
/* global _ */ | ||
export default function BaseCollection ($http, BaseModel) { | ||
export default ['$http', 'BaseModel', function ($http, BaseModel) { | ||
class BaseCollection { | ||
@@ -209,2 +209,2 @@ constructor (models, opts) { | ||
return BaseCollection | ||
} | ||
}] |
@@ -0,4 +1,4 @@ | ||
/* global angular */ | ||
import BaseCollection from './collection.js' | ||
import BaseModel from './model.js' | ||
import angular from 'angular' | ||
@@ -5,0 +5,0 @@ angular.module('fs.collections', []) |
/* eslint-disable no-return-assign */ | ||
import _ from 'underscore' | ||
export default function BaseModel ($http, $rootScope) { | ||
/* global _ */ | ||
export default ['$http', '$rootScope', function ($http, $rootScope) { | ||
class BaseModel { | ||
@@ -174,2 +174,2 @@ parse (res) { | ||
return BaseModel | ||
} | ||
}] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
116404
3
1709
+ Addedgulp-derequire@^2.1.0
+ Addedacorn@7.4.1(transitive)
+ Addedansi-colors@1.1.0(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedansi-wrap@0.1.0(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedbufferstreams@1.1.3(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedd@1.0.2(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedderequire@2.1.1(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-map@0.1.5(transitive)
+ Addedes6-set@0.1.6(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedes6-weak-map@2.0.3(transitive)
+ Addedescope@3.6.0(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedesrecurse@4.3.0(transitive)
+ Addedestraverse@4.3.05.3.0(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedextend-shallow@3.0.2(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedgulp-derequire@2.1.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedplugin-error@1.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedxtend@4.0.2(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)