makeFindAll
can.Model.makeFindAll
makeFindAll is a hook that lets you define special findAll behavior.
It is a generator function that lets you return the function that will
actually be called when findAll is called.
can.Model.makeFindAll: function(findAllData) -> findAll
Returns the external findAll method given the implemented findAllData function.
Parameters
-
findAllData
{findAllData(params)}findAll is implemented with a
String, ajax settings object, or findAllData function. If it is implemented as aStringor ajax settings object, those values are used to create a findAllData function.The findAllData function is passed to
makeFindAll.makeFindAllshould usefindAllDatainternally to get the raw data for the request.
Returns
{function(params, success, error)}
Returns function that implements the external API of findAll.
Use
When a user calls
MyModel.findAll({}), the function returned bymakeFindAllwill be called. Here you can specify what you want to happen before the real request for data is made. Call the function passed infindAllDatawithparamsto make the AJAX request, or whatever the external request for data normally does.makeFindAllcan be used to implement base models that perform special behavior, like caching, or adding special parameters to the request object.makeFindAllis 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 and manually convert it to model instances with models.Caching
The following uses
makeFindAllto create a baseCachedModel:The following Todo model will never request the same list of todo's twice: