ReviewOS

stacks/stx

feat(components): add a signal-based component model helper and complete named-model modifiers

#1965
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Problem

stx already transforms v-model on components into a prop plus an update event, including named models. Component authors still have to connect incoming reactive props to outgoing updates manually.

A first-class model helper would make TextInput, Switch, Select, and Dialog-style components easier to author consistently.

Existing foundation

Reviewed at 7d93c4c: vue-template.ts supports named v-model transforms but explicitly leaves their modifiers unfinished. useReactiveProp and defineEmits provide related primitives.

The repository already uses defineModel for database models. Choose a non-conflicting component API name (for example useModel), rather than repurposing that name.

Scope and acceptance criteria

  • Expose a signal-shaped helper for a default model and named models.
  • Parent updates propagate into the child; child writes emit the appropriate update event.
  • Support multiple independent models on one component without feedback loops.
  • Define defaults, typing, and supported modifier/transform semantics; do not silently discard named modifiers.
  • Keep module and generated-browser implementations consistent.
  • Verify behavior using real component interactions, including teardown and re-mount.
  • Document the pattern and adopt it in a small representative subset of @stacksjs/components.

Prior art: Vue component v-model.

9 days ago

Implemented on main in 3717fe7 and 5d5f3fa. Added signal-based useModel (default and named models), modifier transport and transforms, lifecycle cleanup, module/browser parity, typed declarations, and TextInput/Switch adoption with legacy events preserved. Real-browser tests cover two-way bindings and teardown/remount; separate tests cover type safety and minified bundling. Documentation: docs/features/component-models.md. CI is green for lint, typecheck, tests, and publish: https://github.com/stacksjs/stx/actions/runs/35995782896 . The helper is named useModel to avoid the existing database defineModel API.

Sign in to comment on this issue.