store
Make a store of objects to use when making requests against fixtures.
can.fixture.store(count, make[, filter])
Parameters
-
count
{Number}
The number of items to create.
-
make
{function()}
A function that will return the JavaScript object. The make function is called back with the id and the current array of items.
-
filter
{function()}
OptionalA function used to further filter results. Used for to simulate server params like searchText or startDate. The function should return true if the item passes the filter, false otherwise. For example:
function(item, settings){ if(settings.data.searchText){ var regex = new RegExp("^"+settings.data.searchText) return regex.test(item.name); } }
Returns
{can.fixture.Store}
A generator object providing fixture functions for findAll, findOne, create, update and destroy.
can.fixture.store(items[, comparator])
Parameters
-
items
{Array}
An array of JavaScript objects that represent data from response.
-
comparator
{Object}
OptionalAn object that specifies how to compare properties. Check can.Object.same for more details.
Returns
{can.fixture.Store}
A generator object providing fixture functions for findAll, findOne, create, update and destroy.
can.fixture.store(count, generator(index,items))
is used to create a store of items that can simulate a full CRUD service. Furthermore, the store can do filtering, grouping, sorting, and paging.Basic Example
The following creates a store for 100 todos:
todoStore
's methods:Can be used to simulate a REST service like:
These fixtures, combined with a can.Model that connects to these services like:
... allows you to simulate requests for all of owner 5's todos like:
Example with items and comparator
The following creates a store with three items:
Comparator defines following rules:
name
attribute is compared case-insensitively,city
attribute is ignored while other attributes are compared by default.