Skip to content

Commit

Permalink
Add JSDoc for @cached
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Sep 8, 2023
1 parent f8001db commit c2b9055
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/@ember/-internals/metal/lib/cached.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,39 @@
import { DEBUG } from '@glimmer/env';
import { createCache, getValue } from '@glimmer/validator';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
/**
* @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 const cached: PropertyDecorator = (...args: any[]) => {
const [target, key, descriptor] = args;

Expand Down

0 comments on commit c2b9055

Please sign in to comment.