feat(core): add DomRef API in developer preview#56544
Closed
devknoll wants to merge 1 commit intoangular:mainfrom
Closed
feat(core): add DomRef API in developer preview#56544devknoll wants to merge 1 commit intoangular:mainfrom
devknoll wants to merge 1 commit intoangular:mainfrom
Conversation
Add DomRef as a safer and more ergonomic API compared to ElementRef. A DomRef is accessed by calling it, similar to a signal. Additionally, it ties result availability to rendering: it does not allow a reference to be unwrapped until after it has had an opportunity to render.
JeanMeche
reviewed
Jun 21, 2024
JeanMeche
reviewed
Jun 21, 2024
| // This class acts as a DI token for DomRef. | ||
| export class DomRef<T> { | ||
| /** @internal */ | ||
| constructor() { |
Member
There was a problem hiding this comment.
Couldn't we make the constructor private instead of throwing ?
Contributor
Author
There was a problem hiding this comment.
I think we would still want to throw anyway, since you could still do new (DomRef as any)() to bypass the private constructor.
I think we'd really just want to declare DomRef as a function that throws:
export function DomRef<T>(): DomRef<T> {
throw new RuntimeError(
RuntimeErrorCode.DOMREF_CONSTRUCTOR,
ngDevMode && 'DomRef cannot be called or constructed',
);
}But I think this might have some other issues.
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Add DomRef as a safer and more ergonomic API compared to ElementRef.
A DomRef is accessed by calling it, similar to a signal. Additionally, it ties result availability to rendering: it does not allow a reference to be unwrapped until after it has had an opportunity to render.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information