Polyfill for RFC 566: @cached
npm install ember-cached-decorator-polyfill







Polyfill for [RFC 566 "@cached decorator"][rfc-566].
[rfc-566]: https://github.com/emberjs/rfcs/pull/566
``bash`
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.
- Ember.js v3.13 or above
- Ember CLI v2.13 or above
- Node.js v14 or above
Add a @cached decorator for memoizing the result of a getter based onfullName
autotracking. In the following example, would only recalculate iffirstName or lastName is updated.
`js
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"][rfc-566].
TypeScript's normal type resolution for an import from @glimmer/tracking@glimmer/tracking
will not find the types provided by this polyfill, since the actual package does not include an export for cache.
In order for TypeScript to recognize the extra cache export, add an importapp.ts
like this somewhere in your codebase (like or test-helper.ts):
`ts`
import 'ember-cached-decorator-polyfill';
Once the upstream types have been updated to reflect RFC 566, this will no
longer be necessary.
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"
]
}