ember-memo-decorator-polyfill v0.1.0-0
ember-memo-decorator-polyfill
Polyfill for RFC 566 "@memo decorator".
Installation
ember install ember-memo-decorator-polyfillFor 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"
],
}
}5 years ago