forked from ember-polyfills/ember-cached-decorator-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
38 lines (37 loc) · 1.13 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import '@glimmer/tracking';
declare module '@glimmer/tracking' {
/**
* @decorator
*
* Memoizes the result of a getter based on autotracking.
*
* The `@cached` decorator can be used on native getters to memoize their return
* values based on the tracked state they consume while being calculated.
*
* By default a getter is always re-computed every time it is accessed. On
* average this is faster than caching every getter result by default.
*
* However, there are absolutely cases where getters are expensive, and their
* values are used repeatedly, so memoization would be very helpful.
* Strategic, opt-in memoization is a useful tool that helps developers
* optimize their apps when relevant, without adding extra overhead unless
* necessary.
*
* @example
*
* ```ts
* import { tracked, cached } from '@glimmer/tracking';
*
* class Person {
* @tracked firstName = 'Jen';
* @tracked lastName = 'Weber';
*
* @cached
* get fullName() {
* return `${this.firstName} ${this.lastName}`;
* }
* }
* ```
*/
export let cached: PropertyDecorator;
}