包详细信息

ember-cached-decorator-polyfill

ember-polyfills353.6kMIT1.0.2

Polyfill for RFC 566: @cached

ember-addon, polyfill, glimmer, tracking

自述文件

ember-cached-decorator-polyfill

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

Polyfill for RFC 566 "@cached decorator".

Installation

ember install ember-cached-decorator-polyfill

For addons, pass the -S flag.

If you're working in an environment with an explicit Babel config (like a V2 addon or an app with ember-cli-babel's { useBabelConfig: true } mode), see "Explicit Babel Config" below.

Compatibility

  • Ember.js v3.13 or above
  • Ember CLI v2.13 or above
  • Node.js v14 or above

Summary

Add a @cached decorator for memoizing the result of a getter based on autotracking. In the following example, fullName would only recalculate if firstName or lastName is updated.

import { tracked, cached } from '@glimmer/tracking';

class Person {
  @tracked firstName = 'Jen';
  @tracked lastName = 'Weber';

  @cached
  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }
}

For detailed usage instructions, refer to the RFC 566 "@cached decorator".

TypeScript Usage

TypeScript's normal type resolution for an import from @glimmer/tracking will not find the types provided by this polyfill, since the actual @glimmer/tracking package does not include an export for cache.

In order for TypeScript to recognize the extra cache export, add an import like this somewhere in your codebase (like app.ts or test-helper.ts):

import 'ember-cached-decorator-polyfill';

Once the upstream types have been updated to reflect RFC 566, this will no longer be necessary.

Explicit Babel Config

In environments where you have an explicit Babel config (like authoring a V2 addon) you will need to configure this polyfill's babel plugin. Add it to your babel.config.js like:

{
  "plugins": [
    "ember-cached-decorator-polyfill/babel-plugin"
  ]
}

更新日志

v1.0.2 (2023-07-26)

:bug: Bug Fix

Committers: 1

v1.0.1 (2022-10-06)

:bug: Bug Fix

v1.0.0 (2022-10-06)

:boom: Breaking Change

  • #177 Updating to blueprint for ember 4.7 (@ef4). Oldest supported Node is now 14, oldest supported Ember is still 3.13.

:rocket: Enhancement

  • #184 Macro-based ember version check (@ef4)
  • #144 Simplify TS setup to avoid needing custom paths (@dfreeman)

:house: Internal

  • #181 convert babel plugin to typescript (@ef4)

Committers: 2

v0.1.4 (2021-07-20)

:bug: Bug Fix

  • #85 fix: Allow the babel plugin to be registered for addons (@dcyriller)

Committers: 1

v0.1.3 (2021-05-20)

:bug: Bug Fix

  • #80 Fix: check for hasPlugin needs the resolved path (@runspired)

:house: Internal

  • #78 Add ember-source@3.24 LTS to CI configuration. (@rwjblue)

Committers: 2

v0.1.2 (2021-05-19)

:bug: Bug Fix

  • #75 Ensure polyfill works properly with Ember 3.27+ (@mydea)

Committers: 1

v0.1.1 (2021-02-16)

:bug: Bug Fix

Committers: 1

v0.1.0 (2020-09-09)

v0.1.0-3 (2020-08-17)

:house: Internal

  • #10 test: add integration / render test (@mydea)

Committers: 1

v0.1.0-2 (2020-08-17)

:bug: Bug Fix

:house: Internal

Committers: 1

v0.1.0-1 (2020-08-11)

v0.1.0-0 (2020-08-10)