Polyfill for RFC 580: Destroyables
npm install ember-destroyable-polyfill







Polyfill for [RFC 580 "Destroyables"][rfc-580].
[rfc-580]: https://github.com/emberjs/rfcs/pull/580
``bash`
ember install ember-destroyable-polyfill
For addons, pass the -S flag.
* Ember.js v3.4 or above
* ember-cli-babel v7.22.1 or above
* Ember CLI v2.13 or above
* Node.js v10 or above
Adds an API for registering destroyables and destructors with Ember's built in
destruction hierarchy.
`js
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.
`js
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"][rfc-580].
TypeScript's normal type resolution for an import from @ember/destroyablenode_modules/@ember/destroyable
will not find this the types provided by this package (since TypeScript
would attempt to resolve it as or under@ember/destroyable
the Definitely Typed location for ). Once the@ember/destroyable API is a documented part of Ember's API, thetsconfig.json
Definitely Typed folks will gladly accept adding that API, but in the
meantime users will need to modify their to tell TypeScript
where these types are.
Add the following to your tsconfig.json:
`js``
{
// ...snip...
"paths": {
// ...snip...
"@ember/destroyable": ["node_modules/ember-destroyable-polyfill"],
}
}