-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
I'd like to define atoms with service dependencies in a shared package and provide different layer implementations per platform (e.g. web vs native).
Currently Atom.runtime(layer) requires the layer at definition time, which couples the atom definitions to a specific implementation.
Would something like this make sense?
// core/runtime.ts - create runtime without layer
export const runtime = Atom.lazyRuntime<Api | Storage>()
// core/atoms.ts - real atoms with real dependencies, defined once
export const users = runtime.atom(Effect.flatMap(Api, a => a.getUsers()))
export const posts = runtime.atom(Effect.flatMap(Api, a => a.getPosts()))
export const userCount = Atom.make((get) => Result.map(get(users), u => u.length))
// web/main.tsx - provide layer
<RegistryProvider initialValues={[Atom.initialValue(runtime.layer, WebApiLayer)]}>
// native/main.tsx - different layer, same atoms
<RegistryProvider initialValues={[Atom.initialValue(runtime.layer, NativeApiLayer)]}>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels