ember-destroyable-polyfill
Polyfill for RFC 580 "Destroyables".
⚠️The RFC is currently in Final Comment Period and hasn't been merged yet.
Things may still change.
Installation
ember install ember-destroyable-polyfill
For addons, pass the -S
flag.
Summary
Adds an API for registering destroyables and destructors with Ember's built in
destruction hierarchy.
import { registerDestructor } from '@ember/destroyable';
class MyComponent extends Component {
constructor() {
let timeoutId = setTimeout(() => console.log('hello'), 1000);
registerDestructor(this, () => clearTimeout(timeoutId));
}
}
The API will also enable users to create and manage their own destroyables, and
associate them with a parent destroyable.
import {
associateDestroyableChild,
registerDestructor
} from '@ember/destroyable';
class TimeoutManager {
constructor(parent, fn, timeout = 1000) {
let timeoutId = setTimeout(fn, timeout);
associateDestroyableChild(parent, this);
registerDestructor(this, () => clearTimeout(timeoutId));
}
}
class MyComponent extends Component {
manager = new TimeoutManager(this, () => console.log('hello'));
}
For detailed usage instructions, refer to the
RFC 580 "Destroyables".