how do you deal with extra records that was created, but not used?

瘦欲@ 提交于 2019-12-12 04:38:06

问题


it's a common pattern to createRecord in the model hook when user enters the route.

Sometimes those records remain unused, and they pops up in certain conditions, i.e. in peekAll query, although that is unwanted. How do deal with them?


回答1:


If creation is the main responsibility for the route, you could destroy model on deactivate route event, for example:

//route
model: function() {
    return this.store.createRecord('modelName');
},

cleanModel: function() {
    var model = this.modelFor( this.routeName );
    if (model.get('isNew')) {
        model.destroyRecord();
    }
}.on('deactivate')

Deactivate event is triggered when the router completely exits this route. It is not executed when the model for the route changes.



来源:https://stackoverflow.com/questions/31151515/how-do-you-deal-with-extra-records-that-was-created-but-not-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!