Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backbone-data

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-data - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

2

bower.json
{
"name": "backbone-data",
"description": "A simple data store for backbone models and collections inspired by Ember Data and angular-data.",
"version": "0.0.7",
"version": "0.0.8",
"homepage": "https://github.com/skaterdav85/backbone-data",

@@ -6,0 +6,0 @@ "authors": [

(function(window, undefined) {
'use strict';
var factory = function(Backbone) {

@@ -12,3 +14,3 @@ var DS = new Backbone.Model();

* @param {String} resourceName The name of the resource when defined
* @param {Array|Object} data A array of object or just a plain json object
* @param {Array|Object} data An array of objects or just a plain json object
*/

@@ -33,3 +35,3 @@ function addIncomplete(resourceName, data) {

/**
* Determine if a model if incomplete or not
* Determine if a model is incomplete or not
* @param {String} resourceName The name of the resource when defined

@@ -57,3 +59,3 @@ * @param {Number|String} id The unique ID of the model to find

* Define a resource for the store
* @param {Object} resourceDefinition An object containing idAttribute, name, collection, and model
* @param {Object} resourceDefinition
*/

@@ -123,3 +125,3 @@ DS.defineResource = function(resourceDefinition) {

return collection.add(data);
return collection.add(data, { merge: true });
} else {

@@ -200,3 +202,2 @@ model = store[resourceName];

return dfd.promise();

@@ -215,3 +216,2 @@ }

if (model) {

@@ -241,3 +241,3 @@ if (isIncomplete(resourceName, id)) {

/**
* Find a model from the store. If not in store, fetches it asynchronously
* Find a model from the store. If not in store, fetches it
* and puts the model in the store

@@ -259,3 +259,3 @@ *

* Request a collection from the server once and inject models in store.
* This does reset the collection for resourceName.
* The temp collection is simply there for fetching the data
*/

@@ -309,6 +309,5 @@ DS.findAll = function(resourceName, options) {

var filteredCollection = new Collection();
var models = collection.filter(predicate);
var models = collection.filter(predicate);
filteredCollection.add(models);
return filteredCollection;

@@ -341,2 +340,7 @@ };

/**
* Simply proxies to Backbone.Model.prototype.destroy
* @param {String} resourceName The name of the resource when defined
* @param {Number|String} id The unique ID of the model to find
*/
DS.destroy = function(resourceName, id) {

@@ -343,0 +347,0 @@ var model = this.get(resourceName, id);

@@ -1,1 +0,1 @@

!function(e){var n=function(n){function t(e,n){var t,r=l[e].idAttribute;a[e]=a[e]||{},_.isArray(n)?n.forEach(function(n){var t=n[r];a[e][t]=!0}):(t=n[r],a[e][t]=!0)}function r(e,n){return a[e]?a[e][n]:!1}function o(e){return l[e].collection?!1:!0}function i(e){var n=new $.Deferred,t=this.get(e);return s[e]?n.resolve(t):t.fetch().then(function(){s[e]=!0,n.resolve(t)}),n.promise()}function c(e,n){var t,o,i,c={},f=$.Deferred();return i=this.get(e,n),t=l[e].idAttribute,i?r(e,n)?i.fetch().then(function(){return delete a[e][n],i}):(f.resolve(i),f.promise()):(c[t]=n,o=new l[e].model(c),o.fetch().then(function(){return u.inject(e,o),o},function(){throw new Error("error fetching model: "+n)}))}var u=new n.Model,l={},f={},a={},d={},s={};return u.defineResource=function(e){if(!e.hasOwnProperty("name")||!e.name)throw new Error("name must be specified when defining a resource");if((!e.hasOwnProperty("idAttribute")||!e.idAttribute)&&e.collection)throw new Error("idAttribute must be specified when defining a resource");if(l[e.name])throw new Error(e.name+" resource has already been defined!");return!e.model&&e.collection&&(e.model=e.collection.prototype.model),e.hasOwnProperty("idAttribute")&&!e.hasOwnProperty("collection")&&(e.collection=n.Collection),l[e.name]=e,f[e.name]||(e.collection?f[e.name]=new e.collection:(e.model=e.model||n.Model,f[e.name]=new e.model)),this},u.createInstance=function(e){return new l[e].model},u.inject=function(e,r,o){var i,c;return f[e]instanceof n.Collection?(o=_.extend({incomplete:!1},o),i=f[e],o.incomplete&&t(e,r),i.add(r)):(c=f[e],c.set(r))},u.get=function(e,n){var t,r,i,c={};return arguments[0]in this.attributes?this.attributes[arguments[0]]:o(e)?f[e]:(i=l[e].idAttribute,r=f[e],r&&(c[i]=n,t=r.findWhere(c))?t:null)},u.getAll=function(e){return f[e]},u.ejectAll=function(e){var n=f[e];n&&n.reset()},u.find=function(e,n){return o(e)?i.call(this,e):c.call(this,e,n)},u.findAll=function(e,n){var t,r=f[e],o=$.Deferred();return"completed"===d[e]?(o.resolve(r),o.promise()):(t=new l[e].collection,t.fetch({success:function(){u.inject(e,t.toJSON(),n),d[e]="completed",o.resolve(r)},error:function(){throw new Error("DS error fetching collection: "+e)}}),o.promise())},u.where=function(e,n){var t=f[e],r=l[e].collection,o=new r,i=t.where(n);return o.add(i),o},u.filter=function(e,n){var t=f[e],r=l[e].collection,o=new r,i=t.filter(n);return o.add(i),o},u.update=function(e,n,t){var r=this.get(e,n);return r.set(t),r.save().then(function(){return r})},u.create=function(e,n){l[e].idAttribute;return n.save().then(function(){return f[e].add(n),n})},u.destroy=function(e,n){var t=this.get(e,n);return t.destroy()},u.reset=function(){return f={},l={},a={},d={},s={},this},e.DS=u,u};"function"==typeof define&&define.amd?define(["backbone"],function(e){return n(e)}):n(e.Backbone)}(window);
!function(e){"use strict";var t=function(t){function n(e,t){var n,r=l[e].idAttribute;a[e]=a[e]||{},_.isArray(t)?t.forEach(function(t){var n=t[r];a[e][n]=!0}):(n=t[r],a[e][n]=!0)}function r(e,t){return a[e]?a[e][t]:!1}function o(e){return l[e].collection?!1:!0}function i(e){var t=new $.Deferred,n=this.get(e);return s[e]?t.resolve(n):n.fetch().then(function(){s[e]=!0,t.resolve(n)}),t.promise()}function c(e,t){var n,o,i,c={},f=$.Deferred();return i=this.get(e,t),n=l[e].idAttribute,i?r(e,t)?i.fetch().then(function(){return delete a[e][t],i}):(f.resolve(i),f.promise()):(c[n]=t,o=new l[e].model(c),o.fetch().then(function(){return u.inject(e,o),o},function(){throw new Error("error fetching model: "+t)}))}var u=new t.Model,l={},f={},a={},d={},s={};return u.defineResource=function(e){if(!e.hasOwnProperty("name")||!e.name)throw new Error("name must be specified when defining a resource");if((!e.hasOwnProperty("idAttribute")||!e.idAttribute)&&e.collection)throw new Error("idAttribute must be specified when defining a resource");if(l[e.name])throw new Error(e.name+" resource has already been defined!");return!e.model&&e.collection&&(e.model=e.collection.prototype.model),e.hasOwnProperty("idAttribute")&&!e.hasOwnProperty("collection")&&(e.collection=t.Collection),l[e.name]=e,f[e.name]||(e.collection?f[e.name]=new e.collection:(e.model=e.model||t.Model,f[e.name]=new e.model)),this},u.createInstance=function(e){return new l[e].model},u.inject=function(e,r,o){var i,c;return f[e]instanceof t.Collection?(o=_.extend({incomplete:!1},o),i=f[e],o.incomplete&&n(e,r),i.add(r,{merge:!0})):(c=f[e],c.set(r))},u.get=function(e,t){var n,r,i,c={};return arguments[0]in this.attributes?this.attributes[arguments[0]]:o(e)?f[e]:(i=l[e].idAttribute,r=f[e],r&&(c[i]=t,n=r.findWhere(c))?n:null)},u.getAll=function(e){return f[e]},u.ejectAll=function(e){var t=f[e];t&&t.reset()},u.find=function(e,t){return o(e)?i.call(this,e):c.call(this,e,t)},u.findAll=function(e,t){var n,r=f[e],o=$.Deferred();return"completed"===d[e]?(o.resolve(r),o.promise()):(n=new l[e].collection,n.fetch({success:function(){u.inject(e,n.toJSON(),t),d[e]="completed",o.resolve(r)},error:function(){throw new Error("DS error fetching collection: "+e)}}),o.promise())},u.where=function(e,t){var n=f[e],r=l[e].collection,o=new r,i=n.where(t);return o.add(i),o},u.filter=function(e,t){var n=f[e],r=l[e].collection,o=new r,i=n.filter(t);return o.add(i),o},u.update=function(e,t,n){var r=this.get(e,t);return r.set(n),r.save().then(function(){return r})},u.create=function(e,t){l[e].idAttribute;return t.save().then(function(){return f[e].add(t),t})},u.destroy=function(e,t){var n=this.get(e,t);return n.destroy()},u.reset=function(){return f={},l={},a={},d={},s={},this},e.DS=u,u};"function"==typeof define&&define.amd?define(["backbone"],function(e){return t(e)}):t(e.Backbone)}(window);

@@ -5,3 +5,3 @@ {

"description": "A simple data store for backbone models and collections inspired by Ember Data and angular-data.",
"version": "0.0.7",
"version": "0.0.8",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

(function(window, undefined) {
'use strict';
var factory = function(Backbone) {

@@ -12,3 +14,3 @@ var DS = new Backbone.Model();

* @param {String} resourceName The name of the resource when defined
* @param {Array|Object} data A array of object or just a plain json object
* @param {Array|Object} data An array of objects or just a plain json object
*/

@@ -33,3 +35,3 @@ function addIncomplete(resourceName, data) {

/**
* Determine if a model if incomplete or not
* Determine if a model is incomplete or not
* @param {String} resourceName The name of the resource when defined

@@ -57,3 +59,3 @@ * @param {Number|String} id The unique ID of the model to find

* Define a resource for the store
* @param {Object} resourceDefinition An object containing idAttribute, name, collection, and model
* @param {Object} resourceDefinition
*/

@@ -123,3 +125,3 @@ DS.defineResource = function(resourceDefinition) {

return collection.add(data);
return collection.add(data, { merge: true });
} else {

@@ -200,3 +202,2 @@ model = store[resourceName];

return dfd.promise();

@@ -215,3 +216,2 @@ }

if (model) {

@@ -241,3 +241,3 @@ if (isIncomplete(resourceName, id)) {

/**
* Find a model from the store. If not in store, fetches it asynchronously
* Find a model from the store. If not in store, fetches it
* and puts the model in the store

@@ -259,3 +259,3 @@ *

* Request a collection from the server once and inject models in store.
* This does reset the collection for resourceName.
* The temp collection is simply there for fetching the data
*/

@@ -309,6 +309,5 @@ DS.findAll = function(resourceName, options) {

var filteredCollection = new Collection();
var models = collection.filter(predicate);
var models = collection.filter(predicate);
filteredCollection.add(models);
return filteredCollection;

@@ -341,2 +340,7 @@ };

/**
* Simply proxies to Backbone.Model.prototype.destroy
* @param {String} resourceName The name of the resource when defined
* @param {Number|String} id The unique ID of the model to find
*/
DS.destroy = function(resourceName, id) {

@@ -343,0 +347,0 @@ var model = this.get(resourceName, id);

@@ -75,2 +75,14 @@ describe('inject()', function() {

});
});
it('should update a model in the store a duplicate record is injected', function() {
DS.inject('person', { id: 2, name: 'Jane S.', age: 24, gender: 'F' });
DS.inject('person', people);
expect(DS.get('person', 2).toJSON()).to.eql({
id: 2,
name: 'Jane',
age: 24,
gender: 'F'
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc