Skip to content

Comments

feat(atoms, react): add single-signal wrapping to injectMappedSignal#337

Open
bowheart wants to merge 1 commit intomasterfrom
bowheart/mapped-signal-wrap
Open

feat(atoms, react): add single-signal wrapping to injectMappedSignal#337
bowheart wants to merge 1 commit intomasterfrom
bowheart/mapped-signal-wrap

Conversation

@bowheart
Copy link
Collaborator

Description

Added support for wrapping a single Signal directly with injectMappedSignal. Previously, injectMappedSignal only accepted an object of signals. Now it accepts either a SignalMap (object) or a single Signal, creating a thin wrapper that keeps the inner signal reference up-to-date.

When wrapping a single signal, the MappedSignal's state is identical to the wrapped signal's state (not wrapped in an object), and all events pass through directly without key prefixes. This is useful for composing signals while maintaining a consistent reference to the wrapped signal across atom reevaluations.

Changes

  • MappedSignal class: Added F (Forwarding) property for single-wrapped signals and single-signal mode handling in set(), send(), r(), and u() methods
  • injectMappedSignal function: Converted to function declaration with two overloads to support both map and single-signal signatures
  • Tests: Added 14 comprehensive tests covering single-signal wrapping functionality, event forwarding, mutations, and type correctness
  • Type safety: Full TypeScript support with StateOf and EventsOf type helpers correctly extracting types for both approaches

All existing tests (445) continue to pass.

…dSignal

Add support for wrapping a single Signal directly with injectMappedSignal,
creating a thin wrapper that keeps the inner signal reference up-to-date
and triggers changes when the reference changes. The MappedSignal's state
is identical to the wrapped signal's state, and events pass through directly.

- Add F (Forwarding) property to MappedSignal for single-wrapped signal
- Implement single-signal mode in set/send/r/u methods
- Add function overloads to injectMappedSignal for both signatures
- Add 14 comprehensive tests for single-signal wrapping functionality
- Ensure all 445 existing tests continue to pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant