can.Model.makeFindAll
can.Model.makeFindAll: function(findAllData) -> findAll
Returns the external findAll
method given the implemented findAllData function.
Parameters
-
{findAllData(params)}
findAll is implemented with a
String
, [can.AjaxSettings ajax settings object], or findAllData function. If it is implemented as aString
or [can.AjaxSettings ajax settings object], those values are used to create a findAllData function.The findAllData function is passed to
makeFindAll
.makeFindAll
should usefindAllData
internally to get the raw data for the request.
Returns
{function(params, success, error)}
Returns function that implements the external API of findAll
.
Use
makeFindAll
can be used to implement base models that perform special behavior.makeFindAll
is passed a findAllData function that retrieves raw data. It should return a function that when called, uses the findAllData function to get the raw data, convert them to model instances with models.Caching
The following uses
makeFindAll
to create a baseCachedModel
:CachedModel = can.Model.extend({ makeFindAll: function(findAllData){ // A place to store requests var cachedRequests = {};
},{})
The following Todo model will never request the same list of todo's twice:
Todo = CachedModel({ findAll: "/todos" },{})
// widget 1 Todo.findAll({})
// widget 2 Todo.findAll({})