open-vault/ui/app/mixins/unload-model-route.js

23 lines
506 B
JavaScript
Raw Normal View History

import Mixin from '@ember/object/mixin';
2018-04-03 14:16:57 +00:00
// removes Ember Data records from the cache when the model
// changes or you move away from the current route
export default Mixin.create({
2018-04-03 14:16:57 +00:00
modelPath: 'model',
unloadModel() {
const model = this.controller.get(this.get('modelPath'));
if (!model || !model.unloadRecord) {
return;
}
this.store.unloadRecord(model);
model.destroy();
},
actions: {
willTransition() {
this.unloadModel();
return true;
},
},
});