Skip to content

Commit

Permalink
refactor(core): export additional methods from primitives/signals (an…
Browse files Browse the repository at this point in the history
…gular#56759)

Export `producerIncrementEpoch` which was missing before, as well as a new
`runPostSignalSetFn` helper. These changes make it easier to write `signal`-
like utilities which don't use the `createSignal` abstraction.

PR Close angular#56759
  • Loading branch information
alxhub authored and thePunderWoman committed Jul 1, 2024
1 parent 2a1291e commit 46b0292
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions goldens/public-api/core/primitives/signals/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export function isReactive(value: unknown): value is Reactive;
// @public
export function producerAccessed(node: ReactiveNode): void;

// @public
export function producerIncrementEpoch(): void;

// @public
export function producerNotifyConsumers(node: ReactiveNode): void;

Expand Down Expand Up @@ -92,6 +95,9 @@ export interface ReactiveNode {
version: Version;
}

// @public (undocumented)
export function runPostSignalSetFn(): void;

// @public (undocumented)
export function setActiveConsumer(consumer: ReactiveNode | null): ReactiveNode | null;

Expand Down
2 changes: 2 additions & 0 deletions packages/core/primitives/signals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export {
isInNotificationPhase,
isReactive,
producerAccessed,
producerIncrementEpoch,
producerNotifyConsumers,
producerUpdateValueVersion,
producerUpdatesAllowed,
Expand All @@ -33,6 +34,7 @@ export {
SignalGetter,
SignalNode,
createSignal,
runPostSignalSetFn,
setPostSignalSetFn,
signalSetFn,
signalUpdateFn,
Expand Down
4 changes: 4 additions & 0 deletions packages/core/primitives/signals/src/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export function signalUpdateFn<T>(node: SignalNode<T>, updater: (value: T) => T)
signalSetFn(node, updater(node.value));
}

export function runPostSignalSetFn(): void {
postSignalSetFn?.();
}

// 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.
Expand Down

0 comments on commit 46b0292

Please sign in to comment.