feat: typed custom events between form and fields#3
Closed
LouisHaftmann wants to merge 1 commit into
Closed
Conversation
Add a bidirectional event channel on top of hookable: fields emit field → form events (the form listens and receives the sender field), and the form emits form → field events (fields listen). Payloads are declared app-wide via a module-augmentable `Register` interface, keyed by direction (`toForm` / `toField`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prototype for a bidirectional, fully-typed custom event channel between a form and its fields, built on top of the existing
hookableinstance.field.events.callHook(name, payload)emits;form.events.hook(name, (payload, field) => …)listens and receives the sender field.form.events.callHook(name, payload)emits (broadcast to all field listeners);field.events.hook(name, payload => …)listens.Registerinterface, keyed by direction:Directions are type-enforced (a form can't emit a
toFormevent, and vice versa), unknown events / wrong payloads are rejected, andvoidevents take no payload.hook/hookOnce/callHooknaming mirrorshookable.Implementation
createHooks()bus per form (separate from lifecyclehooks); names namespaced by direction (toForm:/toField:).eventsfacade added to the form handle and to eachFormField.useFormHandles(vue) aggregateseventsacross forms.Tests
core.test.ts): field→form w/ sender, form→field, broadcast, void payload, direction isolation.types.test-d.ts): typed payloads + sender, direction enforcement, unknown/wrong/missing payloads rejected.Type-check ✓, lint ✓, tests green (only the pre-existing
field > readonlyfailure remains, unrelated).