Instruct lumbar that this attribute should be included in the object returned by model.toJSON()
.
If a serializer function is included, the attribute's value will be passed through this function.
Alternatively, an options object can be passed in with save
and/or load
callbacks that will
The serializer function will be called with two arguments, value
and attribute
. This function should represent a serialized (String
) version of the value.
Note: If no calls are made to Model.persist()
then lumbar will assume that all attributes should be persisted normally as per Backbone.js behaviour.
Instruct lumbar that this attribute should be exposed to views in model.toViewModel()
. Optionally specify a filter function to transform/serialize the attribute's value.
The filter function will be called with two arguments, value
and attribute
.
Note: If no calls are made to Model.expose()
then lumbar will assume that all attributes should be persisted normally as per Backbone.js toJSON()
behaviour.
class MyAuthor extends lumbar.Model
@persist "firstName"
@persist "lastName"
@expose "fullName", ["firstName", "lastName"], (firstName, lastName) ->
"#{firstName} #{lastName}"
class MyNewsItem extends lumbar.Model
@persist "title"
@persist "description"
# @author is a model, save only the model's id
@persist "author",
save: -> @author.id
load: (author_id) -> @author = new MyAuthor(id: author_id)
@persist "updated", -> +new Date()
The following asynchronous methods no longer accept an options
object with success
and failure
callbacks. Instead, they return Promise
objects of jQuery Deferred objects.
lumbar.Model
:
model.save()
model.fetch()
model.destroy()
lumbar.Collection
:
collection.create()
collection.fetch()