Comparing version 0.3.3 to 0.3.4
{ | ||
"name": "brink", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "", | ||
@@ -44,4 +44,4 @@ "main": "./src/brink/brink.js", | ||
"wrench": "~1.5.7", | ||
"yuidocjs": "^0.6.0" | ||
"yuidocjs": "^0.9.0" | ||
} | ||
} |
258
README.md
@@ -10,3 +10,3 @@ # brink.js | ||
- [Publish/Subscribe](#pubsub) (promise-based) | ||
- Models + Collections | ||
- [Data Layer](#data) | ||
- No `get()` or `set()`, uses ES5 property descriptors | ||
@@ -339,2 +339,194 @@ - IE9 + support | ||
<a name="data"></a> | ||
#### Data Layer | ||
Brink's Model, Store and Adapter Classes offer you a flexible and easy way to work with your data layer. | ||
Using `Brink.attr()`, `Brink.belongsTo()` and `Brink.hasMany()` you can define simple or complex model | ||
structures. | ||
```javascript | ||
var MyStore = $b.Store.create(); | ||
var Person = $b.Model.extend({ | ||
primaryKey : 'id', | ||
modelKey : 'person', | ||
adapter : $b.RESTAdapter.create(), | ||
store : MyStore, | ||
schema : $b.Schema.create({ | ||
firstName : $b.attr(String), | ||
lastName : $b.attr(String), | ||
children : $b.hasMany('person'), | ||
spouse : $b.belongsTo('person') | ||
}) | ||
}); | ||
var dad = Person.create({ | ||
firstName : 'John', | ||
lastName : 'Doe' | ||
}); | ||
var mom = Person.create({ | ||
firstName : 'Jane', | ||
lastName : 'Doe' | ||
}); | ||
var child1 = Person.create({ | ||
firstName : 'Mary', | ||
lastName : 'Doe' | ||
}); | ||
var child2 = Person.create({ | ||
firstName : 'Bob', | ||
lastName : 'Doe' | ||
}); | ||
dad.spouse = mom; | ||
dad.children.push(child1, child2); | ||
$b.Q.all([ | ||
mom.save(), | ||
child1.save(), | ||
child2.save() | ||
]).then(function () { | ||
dad.save(); | ||
}); | ||
``` | ||
Both `hasMany()` and `belongsTo()` relationships serialize as the primary key values of the records they represent. | ||
This is why we call `save()` on the mom and children before we save the `dad` record, otherwise they would not have primary keys. | ||
The reverse happens when we de-serialize. This means that if we were to do : | ||
```javascript | ||
var dad = Person.create(); | ||
dad.deserialize({spouse : '123'}); | ||
console.log(dad.spouse); | ||
``` | ||
`dad.spouse` would be a Person instance, not the String value we gave it when we deserialized. | ||
If there is a record with that primary key value in the Store, it will be used, however if there is no | ||
corresponding record in the store, then a new record will be created with it's primary key set to the correct value. | ||
Thus, expanding on the above, if we wanted to get the name of the spouse we could do : | ||
```javascript | ||
var dad = Person.create(); | ||
dad.deserialize({spouse : '123'}); | ||
function logSpouseName () { | ||
console.log(dad.spouse.firstName + ' ' + dad.spouse.lastName); | ||
} | ||
if (dad.spouse.isLoaded) { | ||
logSpouseName(); | ||
} | ||
else { | ||
dad.spouse.fetch().then(logSpouseName); | ||
} | ||
``` | ||
`Brink.attr()`, `Brink.hasMany()` and `Brink.belongsTo()` all take a second argument of `options` when you | ||
are declaring them. | ||
```javascript | ||
var MyStore = $b.Store.create(); | ||
var Name = $b.Model.extend({ | ||
primaryKey : null, | ||
schema : $b.Schema.create({ | ||
firstName : $b.attr(String, {key : 'first_name', defaultValue : 'John'}), | ||
lastName : $b.attr(String, {key : 'last_name', defaultValue : 'Doe'}) | ||
}) | ||
}); | ||
var Person = $b.Model.extend({ | ||
primaryKey : 'id', | ||
modelKey : 'person', | ||
adapter : $b.RESTAdapter.create(), | ||
store : MyStore, | ||
schema : $b.Schema.create({ | ||
name : $b.belongsTo('name', {embedded : true}) | ||
}) | ||
}); | ||
``` | ||
`options` which apply to all `attr()`, `belongsTo()` and `hasMany()` are `key` and `defaultValue`. | ||
`defaultValue` allows you to specify exactly that, a default value to use for all records created. | ||
`key` allows you to specify a different | ||
property name to use in your model, without affecting the serialization or deserialization of your models. | ||
```javascript | ||
var name = Name.create(); | ||
name.deserialize({first_name : 'Bob', last_name : 'Smith'})l | ||
console.log(name.firstName); // Bob | ||
console.log(name.lastName); // Smith | ||
console.log(name.serialize()); // {first_name : 'Bob', last_name : 'Smith'} | ||
``` | ||
`hasMany()` and `belongsTo()` relationships have another option they can use, `embedded`. | ||
Setting `embedded` to true overrides the default behavior of relationships in that they won't serialize | ||
and deserialize as primary keys, instead they will `serialize()` the whole record nested. | ||
```javascript | ||
var MyStore = $b.Store.create(); | ||
var Name = $b.Model.extend({ | ||
primaryKey : null, | ||
schema : $b.Schema.create({ | ||
firstName : $b.attr(String, {key : 'first_name', defaultValue : 'John'}), | ||
lastName : $b.attr(String, {key : 'last_name', defaultValue : 'Doe'}) | ||
}) | ||
}); | ||
var Person = $b.Model.extend({ | ||
primaryKey : 'id', | ||
modelKey : 'person', | ||
adapter : $b.RESTAdapter.create(), | ||
store : MyStore, | ||
schema : $b.Schema.create({ | ||
name : $b.belongsTo('name', {embedded : true}) | ||
}) | ||
}); | ||
var person = Person.create(); | ||
person.deserialize({name : { | ||
first_name : 'Bob', | ||
last_name : 'Smith' | ||
}}); | ||
console.log(person.serialize()); // {name : {first_name : 'Bob', last_name : 'Smith'}} | ||
``` | ||
---------------------------- | ||
@@ -370,39 +562,39 @@ | ||
This software is released under the terms of the MIT License. | ||
This software is released under the terms of the MIT License. | ||
(c) 2015 Taka Kojima (the "Author"). | ||
All Rights Reserved. | ||
(c) 2015 Taka Kojima (the "Author"). | ||
All Rights Reserved. | ||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
Distributions of all or part of the Software intended to be used | ||
by the recipients as they would use the unmodified Software, | ||
containing modifications that substantially alter, remove, or | ||
disable functionality of the Software, outside of the documented | ||
configuration mechanisms provided by the Software, shall be | ||
modified such that the Author's bug reporting email addresses and | ||
urls are either replaced with the contact information of the | ||
parties responsible for the changes, or removed entirely. | ||
Distributions of all or part of the Software intended to be used | ||
by the recipients as they would use the unmodified Software, | ||
containing modifications that substantially alter, remove, or | ||
disable functionality of the Software, outside of the documented | ||
configuration mechanisms provided by the Software, shall be | ||
modified such that the Author's bug reporting email addresses and | ||
urls are either replaced with the contact information of the | ||
parties responsible for the changes, or removed entirely. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
Except where noted, this license applies to any and all software | ||
programs and associated documentation files created by the | ||
Author, when distributed with the Software. | ||
Except where noted, this license applies to any and all software | ||
programs and associated documentation files created by the | ||
Author, when distributed with the Software. |
@@ -13,2 +13,27 @@ $b( | ||
/*********************************************************************** | ||
Adapters are how you interface with your persistence layer. | ||
Adapters receive requests from the store and perform the necessary actions, | ||
returning promises that get resolved when operations are complete. | ||
Generally, you will not interact with Adapters directly, the Store and Models will proxy | ||
requests to your adapters. This allows you to easily swap out Adapters | ||
if you want to change your persistence layer, and even mix and match adapters | ||
for different models. | ||
For help with writing your own Adapter, {{#crossLink "Brink.RESTAdapter"}}{{/crossLink}} | ||
can be used as a good reference implementation. | ||
@class Brink.Adapter | ||
@constructor | ||
@module Brink | ||
@submodule data | ||
************************************************************************/ | ||
__init : function () { | ||
@@ -43,8 +68,60 @@ | ||
/*********************************************************************** | ||
Fetches a record from the persistence layer. | ||
@method fetch | ||
@param {Model} record The record you want to fetch. | ||
@return {Promise} | ||
************************************************************************/ | ||
fetch : $b.F, | ||
/*********************************************************************** | ||
Fetches all records of a Model from the persistence layer. | ||
@method fetchAll | ||
@param {ModelClass} Model The Class you want to fetch records of. | ||
@return {Promise} | ||
************************************************************************/ | ||
fetchAll : $b.F, | ||
/*********************************************************************** | ||
Saves a new record to your persistence layer. | ||
@method createRecord | ||
@param {Model} record The record you want to create. | ||
@return {Promise} | ||
************************************************************************/ | ||
createRecord : $b.F, | ||
/*********************************************************************** | ||
Updates a record in your persistence layer. | ||
@method updateRecord | ||
@param {Model} record The record you want to update. | ||
@return {Promise} | ||
************************************************************************/ | ||
updateRecord : $b.F, | ||
/*********************************************************************** | ||
Deletes a record in your persistence layer. | ||
@method deleteRecord | ||
@param {Model} record The record you want to delete. | ||
@return {Promise} | ||
************************************************************************/ | ||
deleteRecord : $b.F, | ||
/*********************************************************************** | ||
Saves a record in your persistence layer. | ||
@method saveRecord | ||
@param {Model} record The record you want to save. This will call createRecord() | ||
or updateRecord(), depending on whether or not the record is new. | ||
@return {Promise} | ||
************************************************************************/ | ||
saveRecord : function (record) { | ||
@@ -59,2 +136,9 @@ | ||
/*********************************************************************** | ||
Hook for doing anything you need to based on a new Model definition. | ||
@method registerModel | ||
@param {Model} Model | ||
************************************************************************/ | ||
registerModel : function () { | ||
@@ -69,2 +153,2 @@ // Hook for if you need to do any fancy pants stuff... | ||
).attach('$b'); | ||
).attach('$b'); |
@@ -12,2 +12,11 @@ $b( | ||
/*********************************************************************** | ||
Define a Schema attribute. | ||
@method attr | ||
@param {Type} type The value type of the attribute. | ||
@param {Object} options Options for the attribute | ||
@return {ComputedProperty} | ||
************************************************************************/ | ||
return (function make (type, options) { | ||
@@ -14,0 +23,0 @@ |
@@ -12,2 +12,11 @@ $b( | ||
/*********************************************************************** | ||
Define a Schema belongsTo relationship (many to one). | ||
@method belongsTo | ||
@param {String} modelKey The modelKey of the relationship. | ||
@param {Object} options Options for the relationship. | ||
@return {ComputedProperty} | ||
************************************************************************/ | ||
return (function make (mKey, options) { | ||
@@ -67,10 +76,12 @@ | ||
if ( | ||
store && | ||
(typeof val === 'string' || typeof val === 'number') | ||
) { | ||
if (store && val && !(val instanceof $b.__models[mKey])) { | ||
if (typeof val !== 'string' && typeof val !== 'number') { | ||
val = String(val); | ||
} | ||
val = store.findOrCreate(mKey, val); | ||
} | ||
if (val) { | ||
else if (val) { | ||
$b.assert( | ||
@@ -77,0 +88,0 @@ 'Must be a model of type "' + mKey + '".', |
@@ -13,2 +13,11 @@ $b( | ||
/*********************************************************************** | ||
Define a Schema hasMany relationship (one to many). | ||
@method hasMany | ||
@param {String} modelKey The modelKey of the relationship. | ||
@param {Object} options Options for the relationship. | ||
@return {ComputedProperty} | ||
************************************************************************/ | ||
return (function make (mKey, options) { | ||
@@ -15,0 +24,0 @@ |
@@ -0,1 +1,73 @@ | ||
/*********************************************************************** | ||
Brink's Model, Store and Adapter Classes offers you flexible and easy way to work with your data layer. | ||
Using Brink.attr(), Brink.belongsTo() and Brink.hasMany() you can define simple or complex model | ||
structures. | ||
```javascript | ||
var MyStore = $b.Store.create(); | ||
var Person = $b.Model.extend({ | ||
primaryKey : 'id', | ||
modelKey : 'person', | ||
adapter : $b.RESTAdapter.create(), | ||
store : MyStore, | ||
schema : $b.Schema.create({ | ||
firstName : $b.attr(String), | ||
lastName : $b.attr(String), | ||
children : $b.hasMany('person'), | ||
spouse : $b.belongsTo('person') | ||
}) | ||
}); | ||
var dad = Person.create({ | ||
firstName : 'John', | ||
lastName : 'Doe' | ||
}); | ||
var mom = Person.create({ | ||
firstName : 'Jane', | ||
lastName : 'Doe' | ||
}); | ||
var child1 = Person.create({ | ||
firstName : 'Mary', | ||
lastName : 'Doe' | ||
}); | ||
var child2 = Person.create({ | ||
firstName : 'Bob', | ||
lastName : 'Doe' | ||
}); | ||
dad.spouse = mom; | ||
dad.children.push(child1, child2); | ||
$b.Q.all([ | ||
mom.save(), | ||
child1.save(), | ||
child2.save() | ||
]).then(function () { | ||
dad.save(); | ||
}); | ||
``` | ||
Looking at the example above, it might be a bit confusing why we are saving the mom and children | ||
before we save the `dad` record. | ||
The reason for this is that the mom and children do not yet exist, thus if we tried to `serialize()` the `dad` | ||
record they would come back with null primary key values. | ||
@module Brink | ||
@submodule data | ||
************************************************************************/ | ||
$b( | ||
@@ -18,17 +90,128 @@ | ||
/*********************************************************************** | ||
The Model Class is what all records are created from. Models provide | ||
a uniform way to work with your records no matter what your backend | ||
or persistence layer is, even if you mix and match across a project. | ||
@module Brink | ||
@submodule data | ||
@class Brink.Model | ||
@constructor | ||
************************************************************************/ | ||
/*********************************************************************** | ||
The Store instance this model uses. You should only have one Store instance used | ||
across your entire project and models. | ||
@property store | ||
@type Brink.Store | ||
@default null | ||
************************************************************************/ | ||
store : null, | ||
/*********************************************************************** | ||
The Adapter instance you want to use for this model. | ||
@property adapter | ||
@type Brink.Adapter | ||
@default null | ||
************************************************************************/ | ||
adapter : null, | ||
/*********************************************************************** | ||
The modelKey you want to use for the model. This will likely influence your adapter. | ||
i.e. for a RESTAdapter your modelKey would be used in the url for all requests | ||
made for instances of this model. For a MongooseAdapter, | ||
this would likely dictate the name of your tables. | ||
@property modelKey | ||
@type String | ||
@default null | ||
************************************************************************/ | ||
modelKey : null, | ||
/*********************************************************************** | ||
The collectionKey you want to use for the model. Much like modelKey this is the | ||
pluralized form of modelKey. This will be auto-defined as your modelKey + 's' unless | ||
you explicity define it. | ||
@property collectionKey | ||
@type String | ||
@default null | ||
************************************************************************/ | ||
collectionKey : null, | ||
controllerClass : null, | ||
/*********************************************************************** | ||
The property name of the primaryKey you are using for this Model. | ||
@property primaryKey | ||
@type String | ||
@default 'id' | ||
************************************************************************/ | ||
primaryKey : 'id', | ||
/*********************************************************************** | ||
A Brink.Array of all the property names that have been changed since the | ||
last save() or fetch(). | ||
@property dirtyAttributes | ||
@type Brink.Array | ||
@default null | ||
************************************************************************/ | ||
dirtyAttributes : null, | ||
/*********************************************************************** | ||
Whether or not the record is currently saving. | ||
@property isSaving | ||
@type Boolean | ||
@default false | ||
************************************************************************/ | ||
isSaving : false, | ||
/*********************************************************************** | ||
Whether or not the record is currently being fetched. | ||
@property isFetching | ||
@type Boolean | ||
@default false | ||
************************************************************************/ | ||
isFetching : false, | ||
/*********************************************************************** | ||
Whether or not the record has been fetched/loaded. | ||
@property isLoaded | ||
@type Boolean | ||
@default false | ||
************************************************************************/ | ||
isLoaded : false, | ||
/*********************************************************************** | ||
Whether or not the record is currently being deleted. | ||
@property isDeleting | ||
@type Boolean | ||
@default false | ||
************************************************************************/ | ||
isDeleting : false, | ||
/*********************************************************************** | ||
Whether or not the record has one or more changed properties since the | ||
last save() or fetch(). | ||
@property isDirty | ||
@type Boolean | ||
@default false | ||
************************************************************************/ | ||
isDirty : computed(function () { | ||
@@ -38,2 +221,11 @@ return !!get(this, 'dirtyAttributes.length'); | ||
/*********************************************************************** | ||
Opposite of isDirty. | ||
@property isClean | ||
@type Boolean | ||
@default true | ||
************************************************************************/ | ||
isClean : computed(function () { | ||
@@ -43,2 +235,10 @@ return !get(this, 'isDirty'); | ||
/*********************************************************************** | ||
Is the record new? Determined by the existence of a primary key value. | ||
@property isNew | ||
@type Boolean | ||
@default false | ||
************************************************************************/ | ||
isNew : computed(function () { | ||
@@ -48,2 +248,9 @@ return !get(this, 'pk'); | ||
/*********************************************************************** | ||
Get the primary key value of the record. | ||
@property pk | ||
@type String|Number | ||
************************************************************************/ | ||
pk : computed({ | ||
@@ -128,2 +335,10 @@ | ||
/*********************************************************************** | ||
Serialize a record. | ||
@method serialize | ||
@param {Function} filter A custom function to filter out attributes as you see fit. | ||
@return {Object} | ||
************************************************************************/ | ||
serialize : function (filter) { | ||
@@ -176,2 +391,12 @@ | ||
/*********************************************************************** | ||
De-serialize a record. | ||
@method deserialize | ||
@param {Object} json The object containing the properties you want to deserialize. | ||
@param {Boolean} override Whether or not you want to update properties that have already been dirtied. | ||
@param {Function} filter A custom function to filter out attributes as you see fit. | ||
@return {Model} | ||
************************************************************************/ | ||
deserialize : function (json, override, filter) { | ||
@@ -231,2 +456,10 @@ | ||
/*********************************************************************** | ||
Saves any changes to this record to the persistence layer (via the adapter). | ||
Also adds this record to the store. | ||
@method save | ||
@return {Promise} | ||
************************************************************************/ | ||
save : function () { | ||
@@ -253,2 +486,9 @@ | ||
/*********************************************************************** | ||
Fetches and populates this record (via the adapter). | ||
@method fetch | ||
@return {Promise} | ||
************************************************************************/ | ||
fetch : function () { | ||
@@ -274,2 +514,9 @@ | ||
/*********************************************************************** | ||
Deletes this record (via the adapter). Also removes it from the store. | ||
@method delete | ||
@return {Promise} | ||
************************************************************************/ | ||
delete : function () { | ||
@@ -295,2 +542,9 @@ | ||
/*********************************************************************** | ||
Creates and returns a copy of this record, with a null primary key. | ||
@method clone | ||
@return {Model} | ||
************************************************************************/ | ||
clone : function () { | ||
@@ -307,2 +561,10 @@ | ||
/*********************************************************************** | ||
Reverts all changes made to this record since the last save() or fetch(). | ||
@method revert | ||
@return {Model} | ||
************************************************************************/ | ||
revert : function (revertRelationships) { | ||
@@ -309,0 +571,0 @@ |
@@ -14,2 +14,15 @@ $b( | ||
/*********************************************************************** | ||
A basic RESTAdapter implementation, this can be used as a good reference point | ||
for implementing your own adapters or extended to modify the default behavior. | ||
@class Brink.RESTAdapter | ||
@extends Brink.Adapter | ||
@constructor | ||
@module Brink | ||
@submodule data | ||
************************************************************************/ | ||
host : '', | ||
@@ -55,2 +68,2 @@ prefix : '', | ||
).attach('$b'); | ||
).attach('$b'); |
@@ -14,2 +14,13 @@ $b( | ||
/*********************************************************************** | ||
Schemas allow you to define your models properties and relationships. | ||
@module Brink | ||
@submodule data | ||
@class Brink.Schema | ||
@constructor | ||
************************************************************************/ | ||
__init : function (o) { | ||
@@ -16,0 +27,0 @@ |
@@ -17,2 +17,18 @@ $b( | ||
/*********************************************************************** | ||
The store is a glorified cache, with convenience methods to work with your | ||
Adapters to update or query your persistence layer as needed. | ||
By having a Store, you will need to access your persistence layer | ||
much less frequently and you will be able to return records from the | ||
store instantly. | ||
@module Brink | ||
@submodule data | ||
@class Brink.Store | ||
@constructor | ||
************************************************************************/ | ||
init : function () { | ||
@@ -23,2 +39,12 @@ this.__registry = $b.__models; | ||
/*********************************************************************** | ||
Clear the store. Removes all record instances in the store. | ||
This does not in any way affect the persistence layer or call any methods | ||
on the models' adapters. | ||
@method clear | ||
@param {Brink.Model} Model | ||
************************************************************************/ | ||
clear : function () { | ||
@@ -28,2 +54,13 @@ this.__store = {}; | ||
/*********************************************************************** | ||
Adds new record(s) to the store. | ||
This does not in any way affect the persistence layer or call any methods | ||
on the models' adapters. | ||
@method add | ||
@param {String|Model} model The modelKey or Model class to add records for. | ||
@param {Model|Array} records The record or records you want to add to the store. | ||
@return {Brink.Collection} | ||
************************************************************************/ | ||
add : function (mKey, records) { | ||
@@ -61,2 +98,13 @@ | ||
/*********************************************************************** | ||
Removes record(s) from the store. | ||
This does not in any way affect the persistence layer or call any methods | ||
on the models' adapters. | ||
@method remove | ||
@param {String|Model} model The modelKey or Model class to remove records for. | ||
@param {Model|Array} The record or records you want to remove from the store. | ||
@return {Brink.Collection} | ||
************************************************************************/ | ||
remove : function (mKey, records) { | ||
@@ -89,2 +137,10 @@ | ||
/*********************************************************************** | ||
Returns all the records of a specific type in the store. | ||
@method all | ||
@param {String|Model} model The modelKey or Model class of the records you want to get. | ||
@return {Brink.Collection} | ||
************************************************************************/ | ||
all : function (mKey) { | ||
@@ -94,2 +150,11 @@ return this.getCollection(mKey); | ||
/*********************************************************************** | ||
Returns all the records of a specific type from the persistence layer | ||
and adds them to the store. | ||
@method fetchAll | ||
@param {String|Model} model The modelKey or Model class of the records you want to get. | ||
@return {Brink.Collection} | ||
************************************************************************/ | ||
fetchAll : function (mKey) { | ||
@@ -121,2 +186,11 @@ | ||
/*********************************************************************** | ||
Find a record in the store. | ||
@method find | ||
@param {String|Model} model The modelKey or Model class of the record you want to find. | ||
@param {String|Number|Object} q The primary key or an object of parameters you want to match. | ||
@return {Brink.Model} | ||
************************************************************************/ | ||
find : function (mKey, q) { | ||
@@ -151,2 +225,11 @@ | ||
/*********************************************************************** | ||
Find a record in the store by primary key or create one. | ||
@method findOrCreate | ||
@param {String|Model} model The modelKey or Model class of the record you want to find. | ||
@param {String|Number} pk The primary key of the record. | ||
@return {Brink.Model} | ||
************************************************************************/ | ||
findOrCreate : function (mKey, pk) { | ||
@@ -169,2 +252,11 @@ | ||
/*********************************************************************** | ||
Creates a new record and adds it to the store. | ||
@method createRecord | ||
@param {String|Model} model The modelKey or Model class of the record you want to find. | ||
@param {Object} data The data you want to populate the record with. | ||
@return {Brink.Model} | ||
************************************************************************/ | ||
createRecord : function (mKey, data) { | ||
@@ -180,2 +272,11 @@ | ||
/*********************************************************************** | ||
Filters through all records in the store of a specific type and returns matches. | ||
@method filter | ||
@param {String|Model} model The modelKey or Model class of the record you want to find. | ||
@param {Function|Object} q An object of parameters you want to match or a filter function. | ||
@return {Brink.Array} | ||
************************************************************************/ | ||
filter : function (mKey, q) { | ||
@@ -247,2 +348,10 @@ | ||
/*********************************************************************** | ||
Given a modelKey or collectionKey returns the corresponding Model Class. | ||
@method modelFor | ||
@param {String} model The modelKey or collectionKey to get the Class for. | ||
@return {Brink.Model} | ||
************************************************************************/ | ||
modelFor : function (mKey) { | ||
@@ -249,0 +358,0 @@ |
@@ -9,2 +9,3 @@ { | ||
"src/brink/core", | ||
"src/brink/data", | ||
"src/brink/utils" | ||
@@ -15,2 +16,2 @@ ], | ||
} | ||
} | ||
} |
989624
21121
598