Détail du package

ember-destroyable-polyfill

ember-polyfills457.6kMIT2.0.3

Polyfill for RFC 580: Destroyables

ember-addon, polyfill, lifecycle, willDestroy

readme

ember-destroyable-polyfill

CI npm version Download Total Ember Observer Score code style: prettier
Dependabot enabled dependencies Status devDependencies Status

Polyfill for RFC 580 "Destroyables".

Installation

ember install ember-destroyable-polyfill

For addons, pass the -S flag.

Compatibility

  • 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

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".

TypeScript Usage

TypeScript's normal type resolution for an import from @ember/destroyable will not find this the types provided by this package (since TypeScript would attempt to resolve it as node_modules/@ember/destroyable or under the Definitely Typed location for @ember/destroyable). Once the @ember/destroyable API is a documented part of Ember's API, the Definitely Typed folks will gladly accept adding that API, but in the meantime users will need to modify their tsconfig.json to tell TypeScript where these types are.

Add the following to your tsconfig.json:

{
  // ...snip...
  "paths": {
    // ...snip...
    "@ember/destroyable": ["node_modules/ember-destroyable-polyfill"],
  }
}

changelog

v2.0.3 (2021-01-22)

v2.0.2 (2020-09-17)

:bug: Bug Fix

  • #112 Avoid errors when super.init is called multiple times. (@rwjblue)

:house: Internal

Committers: 1

v2.0.1 (2020-08-02)

:bug: Bug Fix

  • #84 Fix types file (must use declare module). (@rwjblue)

Committers: 1

v2.0.0 (2020-08-02)

:boom: Breaking Change

:rocket: Enhancement

:memo: Documentation

  • #81 Add typing information and API documentation back. (@rwjblue)

:house: Internal

Committers: 1

v1.0.2 (2020-07-31)

:bug: Bug Fix

  • #75 Ensure functionality with ember-cli-babel@7.22.0. (@rwjblue)

Committers: 1

v1.0.1 (2020-07-30)

:bug: Bug Fix

  • #74 Ensure interop with ember-cli-babel transpilation of @ember/destroyable (@rwjblue)

:memo: Documentation

Committers: 2

v1.0.0 (2020-07-27)

:boom: Breaking Change

  • #68 Update parent / child destructor ordering to match ember-source@3.20.0 implementation (@rwjblue)
  • #64 Refactor assertDestroyablesDestroyed to match real implementation. (@rwjblue)

:rocket: Enhancement

  • #70 Use destroyables implementation in Ember 3.20+ (@rwjblue)

:bug: Bug Fix

  • #69 Fix private module path for Meta on Ember 3.4 (@rwjblue)

:house: Internal

Committers: 3