Overload cached for non-class use - #21537
Draft
NullVoxPopuli-ai-agent wants to merge 3 commits into
Draft
Conversation
Implements the standalone form proposed in NullVoxPopuli/rfcs#19 -- the memoization companion to RFC 1071's overloaded tracked (emberjs#21471). cached(fn, options?) returns a read-only CachedValue backed by createCache/getValue. options.equals (default Object.is) retains the previous value's identity when a re-computation produces an equivalent result; options.description labels the cache for debugging. The decorator form is unchanged: a legacy decorator invocation always receives three arguments, so the two forms cannot collide. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
NullVoxPopuli-ai-agent
force-pushed
the
overload-cached-for-non-class-use
branch
from
July 31, 2026 02:12
ac806d1 to
e137661
Compare
Calling fn is the expensive part; re-running it only to discard the
result has unclear benefit, so the standalone form takes only
{ description }. Also say cached, not memoized, throughout.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
No new public CachedValue type: get() joins the ReadOnlyReactive interface (an RFC 1071 oversight) and both cachedValue() and the cached() overload return ReadOnlyReactive<Value>. The CachedValue class stays as an internal implementation detail. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the standalone form of
cachedproposed in Overload cached for non-class use — the caching companion to RFC 1071's overloadedtracked, and mirrors that implementation (#21471) throughout.cachedValue(fn, options)in@glimmer/validator, returning RFC 1071'sReadOnlyReactive— noset/update/freeze, it has no storage of its own. Backed bycreateCache/getValue. Per RFC review there is no new public type:get()joins theReadOnlyReactiveinterface (an RFC 1071 oversight) and the implementation class stays internal.options.descriptionlabels the cache for debugging. (An earlier revision proposedoptions.equals; removed per RFC review — callingfnis the expensive part, so re-running it only to discard the result has unclear benefit.)@ember/-internals/metalcacheddispatches between the two forms: a legacy decorator invocation always receives three arguments, socached(fn)/cached(fn, options)can never collide with@cachedon a getter (including static getters). Decorator behavior is unchanged.Reactive/ReadOnlyReactive/TrackedValuetype re-exports from@glimmer/trackingare unchanged.@glimmer/validatorunit tests, glimmer integration-tests rendering tests, metal standalone + assertion tests, an ember rendering test (Component Standalone Cached Values), and type-tests covering overload resolution, read-onlyvalue, and the options object.Draft until the RFC is proposed/accepted upstream.
Test results:
filter=cached33/33 pass,filter=tracked273 pass / 3 skip,type-checkclean,lint:docspass, prettier/eslint clean.🤖 Generated with Claude Code