New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.4 to 0.0.5

67

apidocs.md
API Documentation
=================
### DS.defineResource(resourceDefinition)
## Overview
A resource is the data and meta data associated with a particular RESTful resource. In this library, a resource is broken out into two types: collection resources and model resources. A collection resource is when there can be 1 to many items for a resource. For example, an application could have 1 to many orders. A model resource on the other hand is when you only ever have one instance of something, like a `UserProfile` model tied to the logged-in user's session.
### Collection Resources
##### Synchronous Methods
* DS.defineResource(resourceDefinition) - Create a new resource for the store to manage
* DS.inject(resourceName, model(s)) - Put models into the store
* DS.get(resourceName, id) - Return a single model from the store, or null otherwise
* DS.getAll(resourceName) - Return a collection of models from the store
* DS.where(resourceName, attributes) - Similar to Backbone.Collection's where method but returns a new collection instance of the collection type specified for resourceName
* DS.filter(resourceName, predicate) - Proxies to collection.filter() but returns a new collection instance of the collection type specified for resourceName
* DS.createInstance(resourceName) - Create a new Backbone model instance
* DS.ejectAll(resourceName) - Remove all models from the store for a resource
##### Asynchronous Methods
These methods return a promise
* DS.find(resourceName, id [, options]) - Resolves with the model retrieved and injected into the store
* DS.findAll(resourceName [, options]) - Resolves with the collection instance managed by the store for _resourceName_
* DS.create(resourceName, model) - Resolves with the newly created and injected model
* DS.destroy(resourceName, id) - Destroy a model in the store
* DS.update(resourceName, id, properties) - Update a model in the store and resolves with model
### Model Resources
##### Synchronous Methods
* DS.defineResource(resourceDefinition)
* DS.inject(resourceName, model)
* DS.get(resourceName)
##### Asynchronous Methods
* DS.find(resourceName) - Makes a request for a model only once and resolves with the model
## DS.defineResource(resourceDefinition)
#### Collection Resource
Create a resource by specifying a Backbone model, collection, a unique name, and the property name that uniquely identifies the models for this resource type (the primary key). Creating a resource is the first step to storing your data in the store.
Create a collection resource by specifying a Backbone model, collection, a unique name, and the property name that uniquely identifies the models for this resource type (the primary key).

@@ -31,2 +70,4 @@ ```js

Create a model resource by specifying a Backbone model and a unique name.
```js

@@ -41,3 +82,3 @@ var UserProfile = Backbone.Model.extend();

### DS.inject(resourceName, data);
## DS.inject(resourceName, data);

@@ -58,3 +99,3 @@ Inject an object or an array of objects into the data store. This is particularly useful for when data is bootstrapped onto the page from the server and you need to inject it in the store.

### DS.getAll(resourceName)
## DS.getAll(resourceName)

@@ -86,3 +127,3 @@ Synchronously get all items for a resource in the store and returns the Backbone collection specified for the resource. This method always returns the same collection instance. DS maintains a single collection instance for a given resource.

### DS.get(resourceName, id)
## DS.get(resourceName [, id])

@@ -104,3 +145,3 @@ Synchronously get a single model from the store for a resource.

### DS.findAll(resourceName [, options])
## DS.findAll(resourceName [, options])

@@ -129,3 +170,3 @@ Asynchronously fetch all models once and inject them into the store. Returns a promise. Subsequent requests will just resolve with what is in the cache.

### DS.find(resourceName, id [, options])
## DS.find(resourceName [, id, options])

@@ -178,3 +219,5 @@ Fetch a model if it is not in the data store, or return a model already in the store wrapped up in a resolved promise.

```js
DS.find('profile').then(function(profile) {});
DS.find('profile').then(function(profile) {
// Loads profile model and caches it for subsequent requests
});
```

@@ -196,3 +239,3 @@

### DS.destroy(resourceName, id)
## DS.destroy(resourceName, id)

@@ -208,3 +251,3 @@ Destroy a model in the store

### DS.update(resourceName, id, properties)
## DS.update(resourceName, id, properties)

@@ -224,3 +267,3 @@ Update a model in the store. Delegates to model.save().

### DS.filter(resourceName, predicate)
## DS.filter(resourceName, predicate)

@@ -238,3 +281,3 @@ Proxies to Backbone's collection.filter() but returns a new collection instance of the collection type specified in the resource definition.

### DS.where(resourceName, attributes)
## DS.where(resourceName, attributes)

@@ -241,0 +284,0 @@ Filter models in the store by attributes. Delegates to collection.where() but returns a new collection instance of the proper collection type instead of an array.

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.4",
"version": "0.0.5",
"homepage": "https://github.com/skaterdav85/backbone-data",

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

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

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

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

@@ -6,19 +6,21 @@ Backbone Data

A simple data store for backbone models and collections inspired by Ember Data and angular-data.
A simple data store for Backbone models and collections inspired by Ember Data and angular-data.
### Key Features
## Key Features
* Automatic Caching and Identity Mapping - If a model had already been loaded, asking for it a second time will always return the same object instance. This minimizes the number of round-trips to the server.
* Provides a single point of entry for data access through the global variable _DS_
* Works with existing Backbone models and collections.
* Manages singletons for models and each collection type.
* Many times you'll need the same collection instance in multiple views. Just ask for a collection type from the store (`DS.getAll('person')`, `DS.findAll('person')`) and it will return or resolve with the same collection instance each time.
* Automatic Caching and Identity Mapping
* If a model had already been loaded, asking for it a second time will not make any network requests. This minimizes the number of round-trips to the server.
* Provides a single point of entry for data access through the global variable _DS_ and works with existing Backbone models and collections.
* Manages singletons for models and collections
* Many times you'll need the same collection instance in multiple views. Just ask the store for the resource (`DS.getAll('person')`, `DS.findAll('person')`) and it will return or resolve with the same collection instance each time.
* Maybe you have a single model instance in your application, like a `UserProfile` model. The data store can also manage it as a singleton so that you get the same `UserProfile` instance every time.
* Load models into the store specified as incomplete (lacking details). Extra details about the model can be fetched and cached on subsequent requests. Particularly useful if your models have a lot of data that might not be needed.
* Easily create new filtered collections
* Load models into the store as incomplete. This can be useful if your models have lots of data and not all of it is served upfront. Extra details about the model can be fetched and cached for subsequent requests.
* Easily create new filtered collections that are chainable
* AMD compatible
* 933 bytes gzipped and minified
### Install
[API Documentation and Examples](apidocs.md)
## Install
Grab the minified or unminified file from the _dist_ directory and include it on your page.

@@ -44,43 +46,4 @@

## Collection Resources
## Tests
### Synchronous Methods
* DS.defineResource(resourceDefinition) - Create a new resource for the store to manage
* DS.inject(resourceName, model(s)) - Put models into the store
* DS.get(resourceName, id) - Return a single model from the store, or null otherwise
* DS.getAll(resourceName) - Return a collection of models from the store
* DS.where(resourceName, attributes) - Similar to Backbone.Collection's where method but returns a new collection instance of the collection type specified for resourceName
* DS.filter(resourceName, predicate) - Proxies to collection.filter() but returns a new collection instance of the collection type specified for resourceName
* DS.createInstance(resourceName) - Create a new Backbone model instance
* DS.ejectAll(resourceName) - Remove all models from the store for a resource
### Asynchronous Methods
These methods return a promise
* DS.find(resourceName, id [, options]) - Resolves with the model retrieved and injected into the store
* DS.findAll(resourceName [, options]) - Resolves with the collection instance managed by the store for _resourceName_
* DS.create(resourceName, model) - Resolves with the newly created and injected model
* DS.destroy(resourceName, id) - Destroy a model in the store
* DS.update(resourceName, id, properties) - Update a model in the store and resolves with model
## Model Resources
This is useful if you want to manage a single model in your application, like a user profile that is tied to the user's session.
### Synchronous Methods
* DS.defineResource(resourceDefinition)
* DS.inject(resourceName, model)
* DS.get(resourceName)
### Asynchronous Methods
* DS.find(resourceName) - Makes a request for a model only once and resolves with the model
[API Documentation](apidocs.md)
### Tests
Tests are using Mocha, Chai, and Sinon. Run tests with karma.

@@ -94,3 +57,3 @@

### Build
## Build

@@ -97,0 +60,0 @@ This will create the distribution files in the _dist_ folder

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