vendredi 17 mars 2017

What is a proper way to handle temporary record states in Ember JS?

Let's say I have a list of records that are supposed to have state selected in some current context. I can see two approaches here:

  1. Create an array of objects: records.map(record => { record: record, selected: false }), get and set like `recordObj.set('selected', true). Render this array.

  2. Set property explicitly on record objects: record.set('selected', true). Render RecordArray.

The second one looks much easier than the first as you don't have to manage additional array and objects (this becomes a real hassle).

The problem is that if you set anything on a record object, even a field that is not present in the model, it will still persist through the application (I guess until the model is reloaded and new record object is created?).

How to prevent that and ensure that temporary properties will be clean on every route change? Or how to improve the first approach? Is there anything I'm missing?




Aucun commentaire:

Enregistrer un commentaire