Skip to content

Commit

Permalink
refactor(core): expose SIGNAL_NODE to allow for advanced extensions…
Browse files Browse the repository at this point in the history
… of signals (angular#53571)

For the implementation of input signals, we want to extend the signal
primitive. The basic methods exposed here are not suitable as we'd like
to store additional metadata on the reactive node, and also have a
custom getter (for required inputs and throwing).

To enable this, one small piece was missing. This commit exposes it and
also improves type safety, now that `SignalNode` is typed properly after
the previous commit.

PR Close angular#53571
  • Loading branch information
devversion authored and amilamen committed Jan 26, 2024
1 parent 152a6b2 commit 75646da
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions goldens/public-api/core/primitives/signals/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export function setThrowInvalidWriteToSignalError(fn: () => never): void;
// @public
export const SIGNAL: unique symbol;

// @public (undocumented)
export const SIGNAL_NODE: SignalNode<unknown>;

// @public (undocumented)
export interface SignalGetter<T> extends SignalBaseGetter<T> {
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/primitives/signals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export {createComputed} from './src/computed';
export {defaultEquals, ValueEqualityFn} from './src/equality';
export {setThrowInvalidWriteToSignalError} from './src/errors';
export {consumerAfterComputation, consumerBeforeComputation, consumerDestroy, consumerPollProducersForChange, getActiveConsumer, isInNotificationPhase, isReactive, producerAccessed, producerNotifyConsumers, producerUpdatesAllowed, producerUpdateValueVersion, Reactive, REACTIVE_NODE, ReactiveNode, setActiveConsumer, SIGNAL} from './src/graph';
export {createSignal, setPostSignalSetFn, SignalGetter, signalMutateFn, SignalNode, signalSetFn, signalUpdateFn} from './src/signal';
export {createSignal, setPostSignalSetFn, SIGNAL_NODE, SignalGetter, signalMutateFn, SignalNode, signalSetFn, signalUpdateFn} from './src/signal';
export {createWatch, Watch, WatchCleanupFn, WatchCleanupRegisterFn} from './src/watch';
export {setAlternateWeakRefImpl} from './src/weak_ref';
2 changes: 1 addition & 1 deletion packages/core/primitives/signals/src/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function signalMutateFn<T>(node: SignalNode<T>, mutator: (value: T) => vo
// Note: Using an IIFE here to ensure that the spread assignment is not considered
// a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
// TODO: remove when https://github.com/evanw/esbuild/issues/3392 is resolved.
const SIGNAL_NODE: object = /* @__PURE__ */ (() => {
export const SIGNAL_NODE: SignalNode<unknown> = /* @__PURE__ */ (() => {
return {
...REACTIVE_NODE,
equal: defaultEquals,
Expand Down

0 comments on commit 75646da

Please sign in to comment.