@playfast/reform 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +85 -55
  2. package/package.json +17 -17
  3. package/src/boundary/boundary.test.ts +62 -16
  4. package/src/boundary/boundary.ts +141 -32
  5. package/src/calc/asyncCalc.invalidate.test.ts +516 -18
  6. package/src/calc/asyncCalc.test.ts +207 -175
  7. package/src/calc/asyncCalc.ts +168 -39
  8. package/src/calc/calc.test.ts +3 -5
  9. package/src/calc/calc.ts +44 -18
  10. package/src/calc/calcFamily.test.ts +80 -22
  11. package/src/calc/calcFamily.ts +56 -25
  12. package/src/calc/compose.ts +1 -14
  13. package/src/channel/channel.ts +128 -11
  14. package/src/compose/composition.test.ts +19 -0
  15. package/src/compose/composition.ts +346 -62
  16. package/src/compose/props.ts +13 -6
  17. package/src/compose/provide.ts +187 -46
  18. package/src/compose/slot.ts +156 -19
  19. package/src/compose/structure.test.ts +6 -3
  20. package/src/compose/structure.ts +106 -13
  21. package/src/compose/ui.test.ts +19 -3
  22. package/src/compose/ui.ts +147 -54
  23. package/src/compose/ui.typecheck.ts +40 -4
  24. package/src/definition/definition.ts +22 -9
  25. package/src/event/event.fromSource.test.ts +172 -0
  26. package/src/event/event.test.ts +10 -0
  27. package/src/event/event.ts +102 -18
  28. package/src/feature/feature.mount.test.ts +123 -56
  29. package/src/feature/feature.test.ts +67 -63
  30. package/src/feature/feature.ts +1317 -197
  31. package/src/feature/feature.typecheck.ts +253 -61
  32. package/src/graph/closure.ts +403 -0
  33. package/src/index.ts +171 -245
  34. package/src/internal/bucketCache.ts +39 -0
  35. package/src/internal/capture.ts +9 -4
  36. package/src/internal/env.ts +1 -3
  37. package/src/internal/errors.ts +21 -10
  38. package/src/internal/queryDriver.ts +120 -15
  39. package/src/internal/queryDriverStore.ts +8 -5
  40. package/src/internal/queryDriverTypes.ts +3 -1
  41. package/src/internal/reuse.test.ts +10 -3
  42. package/src/internal/reuse.ts +5 -2
  43. package/src/internal/scheduler.ts +4 -1
  44. package/src/internal/sources.ts +25 -11
  45. package/src/internal/track.ts +3 -2
  46. package/src/internal.ts +222 -0
  47. package/src/namespace/namespace.ts +46 -25
  48. package/src/procedure/procedure.ts +38 -11
  49. package/src/reducer/reducer.ts +78 -34
  50. package/src/remote/remoteState.test.ts +515 -339
  51. package/src/remote/remoteState.ts +572 -107
  52. package/src/remote/remoteState.typecheck.ts +47 -23
  53. package/src/runtime/appRuntime.activation.test.ts +100 -0
  54. package/src/runtime/appRuntime.test.ts +157 -105
  55. package/src/runtime/appRuntime.ts +394 -33
  56. package/src/runtime/eventBudget.test.ts +1 -4
  57. package/src/runtime/eventBudget.ts +9 -8
  58. package/src/runtime/hardening.test.ts +4 -9
  59. package/src/runtime/instrumentation.test.ts +174 -192
  60. package/src/runtime/instrumentation.ts +6 -11
  61. package/src/runtime/loop.test.ts +36 -0
  62. package/src/runtime/loop.ts +69 -40
  63. package/src/scene/featureScene.test.ts +4 -2
  64. package/src/scene/scene.ts +234 -64
  65. package/src/scene/seedScene.test.ts +69 -86
  66. package/src/state/state.nominal.typecheck.ts +68 -0
  67. package/src/state/state.test.ts +17 -0
  68. package/src/state/state.ts +79 -26
  69. package/src/state/stateFamily.test.ts +14 -0
  70. package/src/state/stateFamily.ts +55 -22
  71. package/src/state/stateGroup.ts +53 -17
  72. package/src/state/token.ts +40 -10
  73. package/src/synced/syncedStore.ts +46 -23
  74. package/src/testkit/flight.testkit.ts +75 -0
  75. package/src/wire/tree.test.ts +8 -4
  76. package/src/wire/triggers.test.ts +6 -2
  77. package/src/wire/triggers.ts +14 -10
  78. package/src/calc/asyncCalcDefinitions.ts +0 -48
  79. package/src/channel/procedureRegistry.ts +0 -90
  80. package/src/feature/featureBinding.ts +0 -48
  81. package/src/internal/ctx.ts +0 -9
  82. package/src/remote/remoteStateDefinition.ts +0 -135
  83. package/src/remote/remoteStateLayers.ts +0 -118
  84. package/src/remote/remoteStateLiveTypes.ts +0 -59
  85. package/src/remote/remoteStateSend.ts +0 -64
@@ -1,105 +1,389 @@
1
- import { Context, Effect, Layer, type Schema } from 'effect'
1
+ import { Context, Effect, GlobalValue, Layer, MutableRef, Option, Schema, Scope } from 'effect'
2
+ import type { AST } from 'effect/SchemaAST'
2
3
  import type { YieldWrap } from 'effect/Utils'
3
4
  import { type Manifest, definitionClass } from '../definition/definition'
4
- import { type Ctx } from '../internal/ctx'
5
5
  import type { Tracker } from '../internal/track'
6
6
  import { CurrentTracker } from '../internal/track'
7
- import type { SlotClass } from './slot'
7
+ import { type PropsId, type PropsTag, propsTag } from './props'
8
+ import type { AnySlot, AnySlotInstance, SlotClass, SlotInstance } from './slot'
8
9
  import type { Structure } from './structure'
9
- import type { UiClass, UiContract } from './ui'
10
- import { Props } from './props'
11
- import type { AnyValue } from '../internal/variance'
10
+ import type { UiClass, UiContract, UiReflection } from './ui'
12
11
 
13
12
  export type Frame<C extends UiContract = UiContract> = Structure<C>
14
13
 
15
- export interface RenderEnv {
16
- readonly props: unknown
14
+ export interface RenderEnv<out P = unknown> {
15
+ readonly props: P
17
16
  readonly tracker: Tracker
18
17
  }
19
18
 
20
- export interface CompositionService {
21
- readonly render: (env: RenderEnv) => Effect.Effect<Frame, never, never>
19
+ export type CompositionActivation = Layer.Layer<never, never, never>
20
+
21
+ export interface CompositionService<in out P = unknown, out C extends UiContract = UiContract> {
22
+ readonly render: (env: RenderEnv<P>) => Effect.Effect<Frame<C>, never, never>
23
+ readonly activation: (props: P) => Option.Option<CompositionActivation>
24
+ }
25
+
26
+ export const CompositionIdTypeId: unique symbol = Symbol.for('reform/CompositionId')
27
+ export type CompositionIdTypeId = typeof CompositionIdTypeId
28
+
29
+ export interface CompositionId<
30
+ out N extends string,
31
+ out Identity = unknown,
32
+ out RequiredSlots = unknown,
33
+ > {
34
+ readonly [CompositionIdTypeId]: {
35
+ readonly name: N
36
+ readonly identity: Identity
37
+ readonly requiredSlots: RequiredSlots
38
+ }
39
+ }
40
+
41
+ type IsExact<Left, Right> = [Left] extends [Right] ? ([Right] extends [Left] ? true : false) : false
42
+
43
+ type IsExactCompositionId<Service, N extends string, Identity> = Service extends {
44
+ readonly [CompositionIdTypeId]: {
45
+ readonly name: infer ServiceName extends string
46
+ readonly identity: infer ServiceIdentity
47
+ }
48
+ }
49
+ ? IsExact<ServiceName, N> extends true
50
+ ? IsExact<ServiceIdentity, Identity>
51
+ : false
52
+ : false
53
+
54
+ type IsAny<T> = 0 extends 1 & T ? true : false
55
+
56
+ export type HasExactCompositionId<Services, N extends string, Identity> =
57
+ IsAny<Services> extends true
58
+ ? false
59
+ : true extends IsExactCompositionId<Services, N, Identity>
60
+ ? true
61
+ : false
62
+
63
+ export type CompositionTag<
64
+ N extends string,
65
+ P,
66
+ C extends UiContract,
67
+ Identity = unknown,
68
+ > = Context.Tag<CompositionId<N, Identity, RequiredSlotIdentities<C>>, CompositionService<P, C>>
69
+
70
+ export type SlotClassesOf<C extends UiContract> = C extends {
71
+ readonly slots: infer Slots extends Record<string, AnySlotInstance>
72
+ }
73
+ ? {
74
+ readonly [K in keyof Slots]: Slots[K] extends SlotInstance<
75
+ infer Child,
76
+ infer SlotName,
77
+ infer SlotIdentity
78
+ >
79
+ ? SlotClass<Child, SlotName, SlotIdentity>
80
+ : never
81
+ }
82
+ : Readonly<Record<PropertyKey, never>>
83
+
84
+ type RequiredSlotIdentity<Slot> =
85
+ Slot extends SlotInstance<infer _Target, infer _Name, infer Identity> ? Identity : never
86
+
87
+ export type RequiredSlotIdentities<C extends UiContract> = C extends {
88
+ readonly slots: infer Slots extends Record<string, AnySlotInstance>
89
+ }
90
+ ? RequiredSlotIdentity<Slots[keyof Slots]>
91
+ : never
92
+
93
+ type CompositionSlots<C extends UiContract> = C extends {
94
+ readonly slots: infer Slots extends Record<string, AnySlotInstance>
22
95
  }
96
+ ? [Slots[keyof Slots]] extends [never]
97
+ ? {}
98
+ : { readonly slots: SlotClassesOf<C> }
99
+ : {}
23
100
 
24
- // Optional fields drive Config extends { props/states: … } inference — cannot be Option
25
- export interface CompositionConfig {
101
+ export type CompositionManifest<
102
+ C extends UiContract = UiContract,
103
+ N extends string = string,
104
+ > = Manifest &
105
+ Omit<CompositionConfig, 'slots' | 'ui'> &
106
+ CompositionSlots<C> & {
107
+ readonly kind: 'Composition'
108
+ readonly name: N
109
+ readonly ui: UiReflection<C>
110
+ }
111
+
112
+ export interface CompositionInstance<out Identity = unknown> {
113
+ readonly _compositionIdentity: Identity
114
+ }
115
+
116
+ export interface CompositionReflection<
117
+ out P = unknown,
118
+ out C extends UiContract = UiContract,
119
+ out S extends ReadonlyArray<unknown> = ReadonlyArray<unknown>,
120
+ out N extends string = string,
121
+ out Identity = unknown,
122
+ > {
123
+ new (): CompositionInstance<Identity>
124
+ readonly manifest: CompositionManifest<C, N>
125
+ readonly Props: P
126
+ readonly Contract: C
127
+ readonly States: S
128
+ readonly parseProps: (input: unknown) => Option.Option<P>
129
+ }
130
+
131
+ export interface CompositionPropsReceiver<in P> {
132
+ readonly acceptsProps: (props: P) => void
133
+ }
134
+
135
+ export type CompositionCapture<Result> = <
136
+ P,
137
+ C extends UiContract,
138
+ S extends ReadonlyArray<unknown>,
139
+ N extends string,
140
+ Identity,
141
+ >(
142
+ composition: CompositionClass<P, C, S, N, Identity>,
143
+ ) => Result
144
+
145
+ export interface AnyComposition extends CompositionReflection {
146
+ readonly capture: <Result>(visit: CompositionCapture<Result>) => Result
147
+ }
148
+
149
+ interface CompositionSchema {
150
+ readonly ast: AST
151
+ }
152
+
153
+ type GeneratorContext<Eff> = [Eff] extends [never]
154
+ ? never
155
+ : [Eff] extends [YieldWrap<Effect.Effect<infer _Success, infer _Error, infer R>>]
156
+ ? R
157
+ : never
158
+
159
+ // Property presence drives Config conditional inference; Option would erase it.
160
+ interface CompositionConfigOptionalFields {
161
+ readonly description: string
162
+ readonly props: CompositionSchema
163
+ readonly states: ReadonlyArray<unknown>
164
+ readonly calcs: ReadonlyArray<unknown>
165
+ readonly events: ReadonlyArray<unknown>
166
+ readonly slots: Record<string, AnySlot>
167
+ }
168
+
169
+ export interface CompositionConfig extends Partial<CompositionConfigOptionalFields> {
26
170
  readonly title: string
27
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
28
- readonly description?: string
29
- // Schema variance needs any in encoded/context; only decoded P is used
30
- // oxlint-disable-next-line reform-rules/no-optional-fields -- drives `Config extends { props: }` inference (PropsOf)
31
- readonly props?: Schema.Schema.AnyNoContext
32
- // oxlint-disable-next-line reform-rules/no-optional-fields -- drives `Config extends { states: … }` inference (StatesOf)
33
- readonly states?: ReadonlyArray<unknown>
34
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
35
- readonly calcs?: ReadonlyArray<unknown>
36
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
37
- readonly events?: ReadonlyArray<unknown>
38
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
39
- readonly slots?: Record<string, SlotClass>
40
- // Manifest carrier only — full UiClass's invariant impl tag would leak C
41
- readonly ui: { readonly manifest: Manifest & { readonly kind: 'Ui' } }
42
- }
43
-
44
- type PropsOf<Config> = Config extends { props: Schema.Schema<infer P, AnyValue> } ? P : unknown
45
-
46
- type StatesOf<Config> = Config extends { states: infer S extends ReadonlyArray<unknown> }
171
+ readonly ui: UiReflection
172
+ }
173
+
174
+ type PropsOf<Config> = Config extends { props: infer PropsSchema }
175
+ ? PropsSchema extends Schema.Schema<infer P, infer _Encoded, infer _Context>
176
+ ? P
177
+ : unknown
178
+ : unknown
179
+
180
+ type EncodedPropsOf<Config> = Config extends { props: infer PropsSchema }
181
+ ? PropsSchema extends Schema.Schema<infer _Props, infer Encoded, infer _Context>
182
+ ? Encoded
183
+ : unknown
184
+ : unknown
185
+
186
+ type StatesOf<Config> = Config extends {
187
+ states: infer S extends ReadonlyArray<unknown>
188
+ }
47
189
  ? S
48
190
  : readonly []
49
191
 
50
192
  export interface CompositionClass<
51
- out P,
52
- out C extends UiContract = UiContract,
193
+ in out P,
194
+ in out C extends UiContract = UiContract,
53
195
  out S extends ReadonlyArray<unknown> = ReadonlyArray<unknown>,
54
- > {
55
- new (): {}
56
- readonly manifest: Manifest & { readonly kind: 'Composition' } & CompositionConfig
196
+ in out N extends string = string,
197
+ in out Identity = unknown,
198
+ >
199
+ extends CompositionReflection<P, C, S, N, Identity>, CompositionPropsReceiver<P> {
57
200
  readonly Props: P
58
201
  readonly Contract: C
59
202
  readonly States: S
60
- readonly tag: Context.Tag<CompositionService, CompositionService>
203
+ readonly identity: symbol
204
+ readonly props: PropsTag<P>
205
+ readonly tag: CompositionTag<N, P, C, Identity>
206
+ readonly capture: <Result>(visit: CompositionCapture<Result>) => Result
61
207
  }
62
208
 
63
- interface UiCarrier<C extends UiContract> {
64
- readonly ui: UiClass<C>
209
+ type CompositionDefinitionStatics<
210
+ P,
211
+ C extends UiContract,
212
+ S extends ReadonlyArray<unknown>,
213
+ N extends string,
214
+ Identity,
215
+ > = Pick<
216
+ CompositionClass<P, C, S, N, Identity>,
217
+ 'manifest' | 'identity' | 'props' | 'parseProps' | 'acceptsProps' | 'tag' | 'capture'
218
+ >
219
+
220
+ interface UiCarrier<C extends UiContract, UiName extends string> {
221
+ readonly ui: UiClass<C, UiName>
65
222
  }
66
223
 
67
- export const make = <const Config extends CompositionConfig, C extends UiContract>(
68
- name: string,
69
- // Constrain ui to full UiClass<C> for inference; stored manifest keeps erased carrier
70
- config: Config & UiCarrier<C>,
71
- ): CompositionClass<PropsOf<Config>, C, StatesOf<Config>> => {
72
- const tag = Context.GenericTag<CompositionService, CompositionService>(
73
- `reform/composition/${name}`,
74
- )
75
- const manifest = { kind: 'Composition' as const, name, ...config }
76
- return definitionClass<CompositionClass<PropsOf<Config>, C, StatesOf<Config>>>({ manifest, tag })
224
+ type ContractSlots<C extends UiContract> = CompositionSlots<C>
225
+
226
+ type ContextFreeProps<Config> = Config extends {
227
+ readonly props: infer PropsSchema
228
+ }
229
+ ? PropsSchema extends Schema.Schema<infer _P, infer _Encoded, infer Context>
230
+ ? [Context] extends [never]
231
+ ? unknown
232
+ : { readonly propsSchemaMustNotRequireServices: never }
233
+ : unknown
234
+ : unknown
235
+
236
+ const compositionDefinitionSequence: MutableRef.MutableRef<number> = GlobalValue.globalValue(
237
+ Symbol.for('reform/CompositionDefinitionSequence'),
238
+ () => MutableRef.make(0),
239
+ )
240
+
241
+ const nextCompositionTagKey = (name: string): string =>
242
+ `reform/composition/${name}/${MutableRef.incrementAndGet(compositionDefinitionSequence)}`
243
+
244
+ export const make =
245
+ <
246
+ const N extends string,
247
+ const Config extends CompositionConfig,
248
+ C extends UiContract,
249
+ const UiName extends string,
250
+ >(
251
+ name: N,
252
+ config: Config & UiCarrier<C, UiName> & ContractSlots<C> & ContextFreeProps<Config>,
253
+ ) =>
254
+ <Self>(): CompositionClass<PropsOf<Config>, C, StatesOf<Config>, N, Self> => {
255
+ const identity = Symbol(name)
256
+ const props = propsTag<PropsOf<Config>>()
257
+ const propsSchema = Schema.make<PropsOf<Config>, EncodedPropsOf<Config>>(
258
+ config.props?.ast ?? Schema.Unknown.ast,
259
+ )
260
+ const parseProps: (input: unknown) => Option.Option<PropsOf<Config>> =
261
+ Schema.decodeUnknownOption(propsSchema)
262
+ const tag = Context.GenericTag<
263
+ CompositionId<N, Self, RequiredSlotIdentities<C>>,
264
+ CompositionService<PropsOf<Config>, C>
265
+ >(nextCompositionTagKey(name))
266
+ const manifest = {
267
+ kind: 'Composition',
268
+ name,
269
+ ...config,
270
+ } satisfies CompositionManifest<C, N>
271
+ const composition = definitionClass<
272
+ CompositionClass<PropsOf<Config>, C, StatesOf<Config>, N, Self>
273
+ >({
274
+ manifest,
275
+ identity,
276
+ props,
277
+ parseProps,
278
+ acceptsProps: () => undefined,
279
+ tag,
280
+ capture: <Result>(visit: CompositionCapture<Result>): Result => visit(composition),
281
+ } satisfies CompositionDefinitionStatics<PropsOf<Config>, C, StatesOf<Config>, N, Self>)
282
+ return composition
283
+ }
284
+
285
+ type CompositionLayerInput<Eff> = Exclude<Exclude<GeneratorContext<Eff>, PropsId>, CurrentTracker>
286
+
287
+ type CompositionActivationLayerInput<Eff> = Exclude<
288
+ Exclude<GeneratorContext<Eff>, PropsId>,
289
+ Scope.Scope
290
+ >
291
+
292
+ export interface ScopedCompositionLiveConfig<
293
+ C extends UiContract,
294
+ RenderEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
295
+ ActivationEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
296
+ > {
297
+ readonly render: () => Generator<RenderEff, Frame<C>, never>
298
+ readonly activate: () => Generator<ActivationEff, void, never>
77
299
  }
78
300
 
79
301
  export const live = <
80
302
  P,
81
303
  C extends UiContract,
304
+ S extends ReadonlyArray<unknown>,
305
+ N extends string,
306
+ Identity,
82
307
  Eff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
83
308
  >(
84
- composition: CompositionClass<P, C>,
309
+ composition: CompositionClass<P, C, S, N, Identity>,
85
310
  body: () => Generator<Eff, Frame<C>, never>,
86
- ): Layer.Layer<CompositionService, never, Exclude<Ctx<Eff>, Props>> => {
87
- const logic = Effect.gen(body)
311
+ ): Layer.Layer<
312
+ CompositionId<N, Identity, RequiredSlotIdentities<C>>,
313
+ never,
314
+ CompositionLayerInput<Eff>
315
+ > => {
316
+ const logic: Effect.Effect<Frame<C>, never, GeneratorContext<Eff>> = Effect.gen(body).pipe(
317
+ Effect.orDie,
318
+ )
88
319
  return Layer.effect(
89
320
  composition.tag,
90
321
  Effect.gen(function* () {
91
- const context = yield* Effect.context<Exclude<Ctx<Eff>, Props>>()
92
- const render = (env: RenderEnv): Effect.Effect<Frame, never, never> =>
93
- // oxlint-disable-next-line reform-rules/no-type-assertion -- the one documented render-boundary erasure: a fully-provided generic body's Structure<C> narrowed back to the contract-agnostic Frame service type
94
- logic.pipe(
95
- Effect.provideService(Props, env.props),
322
+ const context = yield* Effect.context<CompositionLayerInput<Eff>>()
323
+ const render = (env: RenderEnv<P>): Effect.Effect<Frame<C>, never, never> => {
324
+ return logic.pipe(
325
+ Effect.provideService(composition.props, env.props),
96
326
  Effect.provideService(CurrentTracker, env.tracker),
97
327
  Effect.provide(context),
98
- ) as unknown as Effect.Effect<Frame, never, never>
99
- return { render }
328
+ )
329
+ }
330
+ return { render, activation: () => Option.none() }
100
331
  }),
101
332
  )
102
333
  }
103
334
 
104
- export const render = (service: CompositionService, env: RenderEnv): Effect.Effect<Frame, never, never> =>
105
- service.render(env)
335
+ export const liveScoped = <
336
+ P,
337
+ C extends UiContract,
338
+ S extends ReadonlyArray<unknown>,
339
+ N extends string,
340
+ Identity,
341
+ RenderEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
342
+ ActivationEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
343
+ >(
344
+ composition: CompositionClass<P, C, S, N, Identity>,
345
+ config: ScopedCompositionLiveConfig<C, RenderEff, ActivationEff>,
346
+ ): Layer.Layer<
347
+ CompositionId<N, Identity, RequiredSlotIdentities<C>>,
348
+ never,
349
+ CompositionLayerInput<RenderEff> | CompositionActivationLayerInput<ActivationEff>
350
+ > => {
351
+ const renderLogic: Effect.Effect<Frame<C>, never, GeneratorContext<RenderEff>> = Effect.gen(
352
+ config.render,
353
+ ).pipe(Effect.orDie)
354
+ const activationLogic: Effect.Effect<void, never, GeneratorContext<ActivationEff>> = Effect.gen(
355
+ config.activate,
356
+ ).pipe(Effect.orDie)
357
+
358
+ return Layer.effect(
359
+ composition.tag,
360
+ Effect.gen(function* () {
361
+ const renderContext = yield* Effect.context<CompositionLayerInput<RenderEff>>()
362
+ const activationContext =
363
+ yield* Effect.context<CompositionActivationLayerInput<ActivationEff>>()
364
+ const render = (env: RenderEnv<P>): Effect.Effect<Frame<C>, never, never> =>
365
+ renderLogic.pipe(
366
+ Effect.provideService(composition.props, env.props),
367
+ Effect.provideService(CurrentTracker, env.tracker),
368
+ Effect.provide(renderContext),
369
+ )
370
+ const activation = (props: P): Option.Option<CompositionActivation> => {
371
+ const scoped = Layer.scopedDiscard(
372
+ activationLogic.pipe(Effect.provideService(composition.props, props)),
373
+ )
374
+ return Option.some(scoped.pipe(Layer.provide(Layer.succeedContext(activationContext))))
375
+ }
376
+ return { render, activation }
377
+ }),
378
+ )
379
+ }
380
+
381
+ export const render = <P, C extends UiContract>(
382
+ service: CompositionService<P, C>,
383
+ env: RenderEnv<P>,
384
+ ): Effect.Effect<Frame<C>, never, never> => service.render(env)
385
+
386
+ export const activation = <P, C extends UiContract>(
387
+ service: CompositionService<P, C>,
388
+ props: P,
389
+ ): Option.Option<CompositionActivation> => service.activation(props)
@@ -1,8 +1,15 @@
1
1
  import { Context } from 'effect'
2
- import type { AnyValue } from '../internal/variance'
3
2
 
4
- const PropsBase: Context.TagClass<Props, 'reform/Props', AnyValue> = Context.Tag('reform/Props')<
5
- Props,
6
- AnyValue
7
- >()
8
- export class Props extends PropsBase {}
3
+ export const PropsIdTypeId: unique symbol = Symbol.for('reform/PropsId')
4
+ export type PropsIdTypeId = typeof PropsIdTypeId
5
+
6
+ export interface PropsId {
7
+ readonly [PropsIdTypeId]: PropsIdTypeId
8
+ }
9
+
10
+ export type PropsTag<P> = Context.Tag<PropsId, P>
11
+
12
+ export const propsTag = <P>(): PropsTag<P> => Context.GenericTag<PropsId, P>('reform/Props')
13
+
14
+ // Unknown keeps the compatibility reader from leaking untyped props.
15
+ export const Props: PropsTag<unknown> = propsTag<unknown>()