包详细信息

ember-lifeline

ember-lifeline92kMIT7.0.0

Ember.js addon for lifecycle aware async tasks and DOM events.

ember-addon

自述文件

ember-lifeline

CI Build Ember Observer Score npm version Monthly Downloads from NPM Code Style: prettier

Ember applications have long life-cycles. A user may navigate to several pages and use many different features before they leave the application. This makes JavaScript and Ember development unlike Rails development, where the lifecycle of a request is short and the environment disposed of after each request. It makes Ember development much more like iOS or video game development than traditional server-side web development.

This addon introduces several functional utility methods to help manage async, object lifecycles, and the Ember runloop. These tools should provide a simple developer experience that allows engineers to focus on the business domain, and think less about the weird parts of working in a long-lived app.

The documentation website contains more examples and API information.

Installation

ember install ember-lifeline

Usage

Ember Lifeline supports a functional API that enables entanglement - the association of async behavior to object instances. This allows you to write async code in your classes that can be automatically cleaned up for you when the object is destroyed.

Ember's runloop functions, like the example below, don't ensure that an object's async is cleaned up.

import Component from '@ember/component';
import { run } from '@ember/runloop';

export default Component.extend({
  init() {
    this._super(...arguments);

    run.later(() => {
      this.set('date', new Date());
    }, 500);
  },
});

Using ember-lifeline's equivalent, in this case runTask, can help ensure that any active async is cleaned up once the object is destroyed.

import Component from '@ember/component';
import { runTask, runDisposables } from 'ember-lifeline';

export default Component.extend({
  init() {
    this._super(...arguments);

    runTask(
      this,
      () => {
        this.set('date', new Date());
      },
      500
    );
  },

  willDestroy() {
    this._super(...arguments);

    runDisposables(this);
  },
});

For more information and examples, please visit the documentation website.

Contributing

See the Contributing guide for details.

Credit

This addon was developed internally at Twitch, written originally by @mixonic and @rwjblue. It's since been further developed and maintained by scalvert.

The name ember-lifeline was suggested by @nathanhammod.

更新日志

v7.0.0 (2023-05-05)

:boom: Breaking Change

:rocket: Enhancement

  • ember-lifeline, test-app
    • #1140 Created timer util that returns a scaled-down timer value in test environments. (@tgvrssanthosh)

:memo: Documentation

  • ember-lifeline, test-app
  • ember-lifeline
    • #1118 Updates jsdoc strings to represent Octane components (@scalvert)

:house: Internal

Committers: 4

v7.0.0-beta.3 (2022-02-10)

v7.0.0-beta.2 (2022-02-07)

v6.0.2 (2021-05-04)

:memo: Documentation

:house: Internal

Committers: 2

v6.0.1 (2020-09-17)

:bug: Bug Fix

  • #931 Upgrades ember-destroyable-polyfill to fix issue with double _super invocation (@scalvert)

Committers: 1

v6.0.0 (2020-08-03)

:boom: Breaking Change

  • #859 Removing deprecation warnings targeted for 4.0.0 (@scalvert)
  • #852 Convert internal destroyable implementation to use @ember/destroyable (@scalvert)
  • #855 Removes support for Ember 3.4 in ember-try config. (@scalvert)

Committers: 1

v5.1.0 (2020-05-05)

:rocket: Enhancement

:house: Internal

Committers: 3

v5.0.0 (2020-01-09)

:boom: Breaking Change

:house: Internal

  • #622 chore(release): Update release-it changelog configuration (@scalvert)
  • #620 Adding release-it configuration (@scalvert)
  • #470 task(types): Turning noImplicitAny on to flush out remaining type inconsistencies (@scalvert)

Committers: 2

4.1.5 / 2019-6-19

  • Refining styling of documentation
  • Added tests to ensure undefined callbacks are thrown when add/remove DOM events

4.1.4 / 2019-4-25

  • Further exposing types to consumers

4.1.3 / 2019-3-22

  • Fix bug in documentation - page title correction

4.1.2 / 2019-3-21

  • Converts our documentation to use ember-cli-addon-docs (#387)
  • Fixing setupLifelineValidation import in readme (#382)

4.1.1 / 2019-03-12

  • Fixing assertion count error for setupLifelineValidation (#377)

4.1.0 / 2019-03-08

  • Updating docs for pollTaskFor (#375)
  • Updates pollTaskFor to correctly await settled (#374)

v4.0.0 / 2019-03-04

  • Lifeline's minimum node version is 8
  • Fixing TS errors related to handlebars types
  • Updating blueprint to latest
  • Updating param name and docs for poll
  • Implements early return when *Task functions called on destroyed objects

  • Fixes for issues #35 and #120

  • Fixes for issues #130 and #168

v3.1.0 / 2018-12-21

  • Modified throttleTask to accept arguments to be passed to throttled method
  • Made spacing arguments required for throttleTask and debounceTask respectively

v3.0.4 / 2018-06-01

  • Updated dependencies to latest versions, including Ember 3.1.2 and Ember CLI 3.1.4
  • PR - Clean up canceled pending debounce by 2hu12

v3.0.0 / 2018-03-12

  • Instance arrays for tracking task and event dependencies for objects deprecated in favor of using WeakMaps to track the association and eventual tear down of resources
  • APIs expanded to include functional counterparts
  • Mixin surface area reduced in favor of delegating to functional equivalent

v2.0.0 / 2017-11-16

  • New feature - scheduleTask - allows for scheduling tasks via lifeline
  • New feature - registerDisposable - registers a function to be called on destruction of the object
  • Allow calling addEventListener from objects other than components (when passing specific HTMLElement).
  • Ensure this.throttleTask created timers are cleared upon destroy.
  • Upgrade to use Ember's new JS modules API. 🎉
  • Removed ability to add multiple listeners to child elements in single call
  • Removed dependency on jQuery for ContextBoundEventListenersMixin

v1.3.0 / 2017-06-30

  • Introduce cancel* methods

v1.2.1 / 2017-06-30

  • Moving arrays to be lazy-allocated

v1.1.0 / 2017-06-15

  • Fixing deprecation issue with lookupFactory
  • [Bugfix] - Adding assertions to ensure _super has been called in the init chain
  • destruct from ember instead of depending on ember-cli-shims

v1.0.4 / 2017-02-07

  • Added removeEventListener method to DomMixin
  • Refactor DOM mixin tests to use standard setup.

v1.0.3 / 2016-10-31

  • Released v1.0.3

v1.0.2 / 2016-10-31

  • Released v1.0.2

v1.0.1 / 2016-10-31

  • Released v1.0.1

v1.0.0 / 2016-10-31

  • Add DOM helper methods.
  • Add implementation for run based helper methods.