Skip to content

Commit

Permalink
refactor(core): initial test code for setInput to work with input s…
Browse files Browse the repository at this point in the history
…ignals (angular#53571)

At this point, we have the following pieces in place:

* the input signature is implemented
* the compiler properly parses and recognizes signal inputs
* the compiler supports type-checking of signal inputs
* input signal metadata is passed to partial output

This commit adds a naive runtime solution to distinguishing between
signal inputs and decorator inputs when the `property` instruction
invokes. This is not ideal and non-performant as we introduce additional
megamorphic reads for every property instruction invocation, or if we'd
use `instanceof`, introducing a hard dependency on `InputSignal` and
risking potentially slower detection.

This code exists purely for testing, to enable playing with input
signals in the playground. In a future commit, we will pass around the
input signal metadata at runtime and can perform highly optimized checks
to distinguish between signal or non-signal inputs- when assigning
values.

More information: https://docs.google.com/document/d/1FpnFruviKb6BFTQfMAP2AMEqEB0FI7z-3mT_qm7lzX8/edit#heading=h.oloxympe902x

PR Close angular#53571
  • Loading branch information
devversion authored and danieljancar committed Jan 26, 2024
1 parent db6e987 commit 537213e
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 200 deletions.
17 changes: 14 additions & 3 deletions packages/core/src/render3/instructions/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/

import {setActiveConsumer} from '@angular/core/primitives/signals';
import {setActiveConsumer, SIGNAL} from '@angular/core/primitives/signals';

import {InputSignal} from '../../authoring';
import {InputSignalNode} from '../../authoring/input_signal_node';
import {Injector} from '../../di/injector';
import {ErrorHandler} from '../../error_handler';
import {RuntimeError, RuntimeErrorCode} from '../../errors';
Expand Down Expand Up @@ -39,7 +41,7 @@ import {RComment, RElement, RNode, RText} from '../interfaces/renderer_dom';
import {SanitizerFn} from '../interfaces/sanitization';
import {TStylingRange} from '../interfaces/styling';
import {isComponentDef, isComponentHost, isContentQueryHost} from '../interfaces/type_checks';
import {CHILD_HEAD, CHILD_TAIL, CLEANUP, CONTEXT, DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, EMBEDDED_VIEW_INJECTOR, ENVIRONMENT, FLAGS, HEADER_OFFSET, HOST, HostBindingOpCodes, HYDRATION, ID, INJECTOR, LView, LViewEnvironment, LViewFlags, NEXT, PARENT, REACTIVE_TEMPLATE_CONSUMER, RENDERER, T_HOST, TData, TVIEW, TView, TViewType} from '../interfaces/view';
import {CHILD_HEAD, CHILD_TAIL, CLEANUP, CONTEXT, DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, EMBEDDED_VIEW_INJECTOR, ENVIRONMENT, FLAGS, HEADER_OFFSET, HOST, HostBindingOpCodes, HYDRATION, ID, INJECTOR, LView, LViewEnvironment, LViewFlags, NEXT, PARENT, RENDERER, T_HOST, TData, TVIEW, TView, TViewType} from '../interfaces/view';
import {assertPureTNodeType, assertTNodeType} from '../node_assert';
import {clearElementContents, updateTextNode} from '../node_manipulation';
import {isInlineTemplate, isNodeMatchingSelectorList} from '../node_selector_matcher';
Expand Down Expand Up @@ -1304,7 +1306,16 @@ function writeToDirectiveInput<T>(
if (def.setInput !== null) {
def.setInput(instance, value, publicName, privateName);
} else {
(instance as any)[privateName] = value;
// TODO: temporary hack for development testing
if ((instance as any)[privateName]?.[SIGNAL] !== undefined &&
(instance as any)[privateName]?.constructor?.name === 'InputSignal') {
const node =
(((instance as any)[privateName] as InputSignal<unknown, unknown>)[SIGNAL] as
InputSignalNode<unknown, unknown>);
node.applyValueToInputSignal(node, value);
} else {
(instance as any)[privateName] = value;
}
}
} finally {
setActiveConsumer(prevConsumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@
{
"name": "SELF_TOKEN_REGEX"
},
{
"name": "SIGNAL"
},
{
"name": "SIMPLE_CHANGES_STORE"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@
{
"name": "SHARED_ANIMATION_PROVIDERS"
},
{
"name": "SIGNAL"
},
{
"name": "SIMPLE_CHANGES_STORE"
},
Expand Down

0 comments on commit 537213e

Please sign in to comment.