ember-memo-decorator-polyfill
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-0 • Public • Published

ember-memo-decorator-polyfill

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

Polyfill for RFC 566 "@memo decorator".

Installation

ember install ember-memo-decorator-polyfill

For addons, pass the -S flag.

Compatibility

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

Summary

Add a @memo 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, memo } from '@glimmer/tracking';
 
class Person {
  @tracked firstName = 'Jen';
  @tracked lastName = 'Weber';
 
  @memo
  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }
}

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

TypeScript Usage

TypeScript's normal type resolution for an import from @glimmer/tracking will not find this the types provided by this package (since TypeScript would attempt to resolve it as node_modules/@glimmer/tracking or under the Definitely Typed location for @glimmer/tracking).

Once the addition to the @glimmer/tracking API is a documented part of Ember's API, the types will be available upstream, 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...
    "@glimmer/tracking": [
      "node_modules/ember-memo-decorator-polyfill",
      "node_modules/@glimmer/tracking/dist/types"
    ],
  }
}

Package Sidebar

Install

npm i ember-memo-decorator-polyfill

Weekly Downloads

1

Version

0.1.0-0

License

MIT

Unpacked Size

17.4 kB

Total Files

15

Last publish

Collaborators

  • rwjblue
  • pzuraq
  • buschtoens
  • chancancode