2018-09-25 16:28:26 +00:00
|
|
|
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
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Mixin.create({
|
2018-04-03 14:16:57 +00:00
|
|
|
modelPath: 'model',
|
|
|
|
unloadModel() {
|
2019-06-20 13:37:27 +00:00
|
|
|
let { modelPath } = this;
|
|
|
|
let model = this.controller.get(modelPath);
|
2018-04-03 14:16:57 +00:00
|
|
|
if (!model || !model.unloadRecord) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.store.unloadRecord(model);
|
|
|
|
model.destroy();
|
2019-06-20 13:37:27 +00:00
|
|
|
// it's important to unset the model on the controller since controllers are singletons
|
|
|
|
this.controller.set(modelPath, null);
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
willTransition() {
|
|
|
|
this.unloadModel();
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|