MCPcopy Index your code
hub / github.com/angular/angular / createInputSignal

Function createInputSignal

packages/core/src/authoring/input/input_signal.ts:115–151  ·  view source on GitHub ↗
(
  initialValue: T,
  options?: InputOptions<T, TransformT>,
)

Source from the content-addressed store, hash-verified

113 * @param options Additional options for the input. e.g. a transform, or an alias.
114 */
115export function createInputSignal<T, TransformT>(
116 initialValue: T,
117 options?: InputOptions<T, TransformT>,
118): InputSignalWithTransform<T, TransformT> {
119 const node: InputSignalNode<T, TransformT> = Object.create(INPUT_SIGNAL_NODE);
120
121 node.value = initialValue;
122
123 // Perf note: Always set `transformFn` here to ensure that `node` always
124 // has the same v8 class shape, allowing monomorphic reads on input signals.
125 node.transformFn = options?.transform;
126
127 function inputValueFn() {
128 // Record that someone looked at this signal.
129 producerAccessed(node);
130
131 if (node.value === REQUIRED_UNSET_VALUE) {
132 let message: string | null = null;
133 if (ngDevMode) {
134 const name = options?.debugName ?? options?.alias;
135 message = `Input${name ? ` "${name}"` : ''} is required but no value is available yet.`;
136 }
137 throw new RuntimeError(RuntimeErrorCode.REQUIRED_INPUT_NO_VALUE, message);
138 }
139
140 return node.value;
141 }
142
143 (inputValueFn as any)[SIGNAL] = node;
144
145 if (ngDevMode) {
146 inputValueFn.toString = () => `[Input Signal: ${inputValueFn()}]`;
147 node.debugName = options?.debugName;
148 }
149
150 return inputValueFn as InputSignalWithTransform<T, TransformT>;
151}

Callers 2

inputFunctionFunction · 0.90
inputRequiredFunctionFunction · 0.90

Calls 2

inputValueFnFunction · 0.85
createMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…