Docs

Everything You Need to Know

Models

Intro

Truck Tank

Data is the source of all truth in an app. Models provide a powerful way to manage data. You could just use POJO, plain ole JavaScript objects. Many frameworks do. But by doing so you loose the power of models.

Truck models are reactive. When you make changes to a model, it triggers an update in the view it is bound to. In contrast, if you had rendered a view with raw JavaScript data, and then later manipulated that data, you would need to pass the updated data to the view to render it again. Ractive models relieve you of the task of updating views.

Truck models can hold a single object of key value pairs, or an array of objects with key value pairs. Truck views feed on models. When rendering their templates, the views do not care what the data is. They take a model of an object and render one occurrence of the template. But if you provide the same view with a model holding an array of objects, that same view will render its template repeatedly, consuming all the objects in the model's array.

Perhaps the part we like the most about models is the fact that they hide your data. A model is an encapsulation where your data is not accessible except through the model's interface. This protects your data from unintentional modification. You can even query a model to find out when was the last time it was modified. You are not going to be able to do that with a POJO.