Skip to content

Commit 560ae24

Browse files
devversionatscott
authored andcommitted
refactor(core): initial test code for setInput to work with input signals (#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 #53571
1 parent 7fb4a37 commit 560ae24

File tree

13 files changed

+343
-200
lines changed

13 files changed

+343
-200
lines changed

packages/core/src/render3/instructions/shared.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {setActiveConsumer} from '@angular/core/primitives/signals';
9+
import {setActiveConsumer, SIGNAL} from '@angular/core/primitives/signals';
1010

11+
import {InputSignal} from '../../authoring';
12+
import {InputSignalNode} from '../../authoring/input_signal_node';
1113
import {Injector} from '../../di/injector';
1214
import {ErrorHandler} from '../../error_handler';
1315
import {RuntimeError, RuntimeErrorCode} from '../../errors';
@@ -39,7 +41,7 @@ import {RComment, RElement, RNode, RText} from '../interfaces/renderer_dom';
3941
import {SanitizerFn} from '../interfaces/sanitization';
4042
import {TStylingRange} from '../interfaces/styling';
4143
import {isComponentDef, isComponentHost, isContentQueryHost} from '../interfaces/type_checks';
42-
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';
44+
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';
4345
import {assertPureTNodeType, assertTNodeType} from '../node_assert';
4446
import {clearElementContents, updateTextNode} from '../node_manipulation';
4547
import {isInlineTemplate, isNodeMatchingSelectorList} from '../node_selector_matcher';
@@ -1304,7 +1306,16 @@ function writeToDirectiveInput<T>(
13041306
if (def.setInput !== null) {
13051307
def.setInput(instance, value, publicName, privateName);
13061308
} else {
1307-
(instance as any)[privateName] = value;
1309+
// TODO: temporary hack for development testing
1310+
if ((instance as any)[privateName]?.[SIGNAL] !== undefined &&
1311+
(instance as any)[privateName]?.constructor?.name === 'InputSignal') {
1312+
const node =
1313+
(((instance as any)[privateName] as InputSignal<unknown, unknown>)[SIGNAL] as
1314+
InputSignalNode<unknown, unknown>);
1315+
node.applyValueToInputSignal(node, value);
1316+
} else {
1317+
(instance as any)[privateName] = value;
1318+
}
13081319
}
13091320
} finally {
13101321
setActiveConsumer(prevConsumer);

packages/core/test/bundling/animations-standalone/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@
431431
{
432432
"name": "SELF_TOKEN_REGEX"
433433
},
434+
{
435+
"name": "SIGNAL"
436+
},
434437
{
435438
"name": "SIMPLE_CHANGES_STORE"
436439
},

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@
479479
{
480480
"name": "SHARED_ANIMATION_PROVIDERS"
481481
},
482+
{
483+
"name": "SIGNAL"
484+
},
482485
{
483486
"name": "SIMPLE_CHANGES_STORE"
484487
},

0 commit comments

Comments
 (0)