Models represent data, and implement properties, methods, and virtuals depending on how you need to interact with that data. Just like views, models are also extendable.
npm install mojo-models --save-exact
base model constructor
properties- values to set onto the view. This could be anything.
application- (optional) the application.
Application.mainwill be set if this is omitted.
The raw data set on the model - this is usually transformed into something the model can use via
deserialize takes the
data property on the model, and transforms the returned values as additional properties on the model.
serializes data. This is an alias to
Persistence layer for models / collections. Also adds the methods
persist is present, and calls
onLoad- onLoad callback function. Expects an
datais set as the
dataproperty on the model, and gets
Note that this method can be called only once during the lifetime of the model. If you want to reload the model, you'll need to call the
Reloads the model. This can be called many times.
model.load. Calls the
persist.save function, and sets result to
data to be deserialized on the model.
Removes the model. Note that if the model is part of a
models.Collection, the model will automatically be removed from the collection.
willSave- emitted when the model is about to be saved
didSave- emitted when the model has been saved
willRemove- emitted when the model is about to be removed
didRemove- emitted when the model has been removed
See above for example.
Virtual properties allow you to load external resources on demand. This is especially useful when you're data-binding a model property to a view layer, and only what to load what the user currently needs.
Note that virtual properties are triggered when they are data-bound.
Bindings allow you to compute properties on models.