open-nomad/ui/app/mixins/with-watchers.js
Michael Lange 2282f3243a Use willTransition instead of deactivate to cancel requests
deactivate happens _after_ the new route's model hook, which
results in the possibility of canceling new requests right
after they are made rather than existing open connections
2018-03-05 09:32:05 -08:00

17 lines
407 B
JavaScript

import Mixin from '@ember/object/mixin';
import { computed } from '@ember/object';
import { assert } from '@ember/debug';
export default Mixin.create({
watchers: computed(() => []),
actions: {
willTransition() {
this.get('watchers').forEach(watcher => {
assert('Watchers must be Ember Concurrency Tasks.', !!watcher.cancelAll);
watcher.cancelAll();
});
},
},
});