mirror of
https://github.com/Effect-TS/effect.git
synced 2026-11-28 02:36:24 +08:00
7.5 KiB
7.5 KiB
@effect/atom-solid bindings
Summary
Add a new @effect/atom-solid package that provides SolidJS bindings for the Effect Atom modules, mirroring the @effect/atom-react feature set and behavior (except ScopedAtom) while adopting Solid naming conventions.
Background
The repository currently ships @effect/atom-react with React hooks and a registry provider, but there is no SolidJS equivalent. Solid users need a first-party package that integrates effect/unstable/reactivity atoms with Solid reactivity and Suspense, with a compatible API surface.
Goals
- Provide a SolidJS package at
packages/atom/solidexporting@effect/atom-solid. - Match the
@effect/atom-reactbehavior for Atom reading, writing, subscriptions, and AsyncResult handling. - Use Solid naming (
create*) instead of React hook names. - Deliver docs and tests mirroring the React package (excluding SSR and ScopedAtom).
Non-goals
- Implementing
ScopedAtomin Solid. - Adding SSR-specific behavior or server snapshot semantics.
- Changing
effect/unstable/reactivityAtom/AtomRegistry behavior.
Requirements
Package layout
- New package directory:
packages/atom/solid. - Package name:
@effect/atom-solid. - Provide
package.json,tsconfig.json,README.md,LICENSE,docgen.json,vitest.config.ts, andvitest.setup.ts, mirroring the structure ofpackages/atom/reactwith Solid-specific dependencies. - Exports map should include
.and./*entries forsrc/*.ts, and publish config fordistoutputs. - Ensure repo tooling includes the new package where required (tsconfig references, docgen discovery, workspace filters) so
codegen,build, anddocgenpick it up.
Dependencies
solid-jsas a peer dependency (Solid 1.x).- Testing peer/dev dependencies for Solid testing (
@solidjs/testing-library,jsdom), aligned with how@effect/atom-reactdeclares testing peers. effectas a workspace dependency.
Public API (Solid naming)
Mirror the React bindings (except ScopedAtom) with Solid-style names:
createAtomInitialValues(fromuseAtomInitialValues).createAtomValue(fromuseAtomValue).createAtomMount(fromuseAtomMount).createAtomSet(fromuseAtomSet).createAtomRefresh(fromuseAtomRefresh).createAtom(fromuseAtom).createAtomSuspense(fromuseAtomSuspense).createAtomSubscribe(fromuseAtomSubscribe).createAtomRef,createAtomRefProp,createAtomRefPropValue(fromuseAtomRef*).RegistryContext,RegistryProvider.
Naming is Solid-first (no use* aliases) while keeping signatures and behavior equivalent to React where feasible.
Registry context and provider
- Provide
RegistryContextcreated viasolid-jscreateContext, defaulting toAtomRegistry.make({ scheduleTask, defaultIdleTTL: 400 }). - Implement
scheduleTaskfor Solid using a cancellable scheduler (e.g.setTimeout(0)returning a disposer). RegistryProvidercreates a registry once per provider instance, keeps it stable across reactive updates, and disposes it on cleanup.- Support provider options:
initialValues?: Iterable<[Atom.Atom<any>, any]>scheduleTask?: (f: () => void) => () => voidtimeoutResolution?: numberdefaultIdleTTL?: number
Hook semantics (Solid equivalents)
createAtomValue(atom, map?)returns a SolidAccessorthat tracks the Atom in the current registry;mapcreates a derived Atom once and tracks it.createAtomInitialValuessets initial values once per registry/Atom pair (same WeakSet semantics as React).createAtomMountensures the Atom is mounted while the calling owner is alive.createAtomSetreturns a setter; whenmodeispromiseorpromiseExitfor AsyncResult atoms, it returns an async setter matching React behavior.createAtomRefreshreturns a function that refreshes the Atom.createAtomreturns[Accessor<R>, write]matchingcreateAtomValue+createAtomSet.createAtomSubscribesubscribes to Atom changes and cleans up on owner disposal.createAtomRefreturns anAccessorthat tracks aAtomRefvalue via subscription.createAtomRefPropandcreateAtomRefPropValuemirror the React helpers but in Solid accessor form.
Suspense behavior
createAtomSuspensesupports the samesuspendOnWaitingandincludeFailureoptions as React.- It should integrate with Solid Suspense (client-side only) by throwing a Promise while the Atom is
Initial(and optionallywaiting), and exposing the resolved value once ready. - When
includeFailureis false, failures are surfaced as thrown errors (to be handled by Solid error boundaries).
Documentation
packages/atom/solid/README.mdmirrors the React package with an API docs link:https://effect-ts.github.io/effect/docs/atom-solid.docgen.jsonconfigured similarly to the React package, with correctsrcLinkforpackages/atom/solid/src/.- JSDoc headers with
@since 1.0.0and categories consistent with atom-react modules.
Testing
- Add a Solid test suite under
packages/atom/solid/testusing@solidjs/testing-library. - Mirror key React tests where relevant:
- Reading values from basic and computed Atoms.
- Updating values when registry sets an Atom.
createAtomsetter semantics (including functional update form).- AsyncResult +
createAtomSuspensesuccess/failure behaviors. createAtomInitialValuesonly applies once.createAtomRefandcreateAtomRefPropValueupdates.
- Exclude SSR-specific tests and ScopedAtom tests.
Implementation plan
- Scaffold
packages/atom/solidwith baseline files (package.json,README.md,LICENSE,tsconfig.json,docgen.json,vitest.config.ts,vitest.setup.ts,srcfolder) and minimal exports so the package builds in isolation. - Implement
RegistryContextandRegistryProviderinpackages/atom/solid/src/RegistryContext.tsusing Solid context and lifecycle primitives, including configurablescheduleTaskand cleanup disposal. - Implement core hooks in
packages/atom/solid/src/Hooks.tsfor value access, mount, set, refresh, and subscribe (no AtomRef helpers yet); return Solid accessors/setters as specified. - Add tests for core hooks in
packages/atom/solid/test/index.test.tsx(basic value, computed, updates, createAtom setter behavior, createAtomInitialValues). - Implement AtomRef helpers (
createAtomRef,createAtomRefProp,createAtomRefPropValue) inpackages/atom/solid/src/Hooks.ts. - Add tests covering AtomRef helpers.
- Implement
createAtomSuspensefor AsyncResult atoms with Solid Suspense integration and error propagation rules. - Add AsyncResult/suspense tests (success and failure) in the Solid test suite.
- Add module exports and run
pnpm codegento generate the barrelpackages/atom/solid/src/index.ts(do not hand-edit). - Add or update package documentation (
README.md,docgen.json) and update.specs/README.mdwith a link to this spec.
Validation
pnpm codegenpnpm lint-fixpnpm test packages/atom/solid/test/index.test.tsxpnpm check(runpnpm cleanand re-run if it fails)pnpm buildpnpm docgen
Acceptance criteria
@effect/atom-solidpackage exists underpackages/atom/solidand builds via repository scripts.- Public API matches the specified Solid naming and behavior, excluding
ScopedAtomand SSR. - Solid tests cover the core Atom interactions and AsyncResult suspense behaviors.
- Documentation is published via docgen and the spec is listed in
.specs/README.md. - All validation steps pass.