Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSDoc for @cached for the built-in types #20543

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add JSDoc for @cached
  • Loading branch information
NullVoxPopuli committed Sep 8, 2023

Verified

This commit was signed with the committer’s verified signature.
commit c2b90552bf9be95b6ae9989551aadef2c5495fa4
34 changes: 33 additions & 1 deletion packages/@ember/-internals/metal/lib/cached.ts
Original file line number Diff line number Diff line change
@@ -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;