refactor(core): make state transforms synchronous

This commit is contained in:
Dax Raad 2026-07-16 13:55:14 -04:00
commit 72af084dc1
2 changed files with 8 additions and 11 deletions

View file

@ -6,9 +6,9 @@ import { Clock, Context, Deferred, Effect, Scope, Semaphore } from "effect"
* A replayable transform applied to a draft during reload.
*
* Domain drafts expose readable and writable state while preserving concise
* plugin/config code. Transforms may perform Effects before returning.
* plugin/config code. Transforms synchronously rebuild derived state.
*/
type TransformCallback<DraftApi> = (draft: DraftApi) => Effect.Effect<void> | void
type TransformCallback<DraftApi> = (draft: DraftApi) => void
export type MakeDraft<State, DraftApi> = (state: State) => DraftApi
export interface Registration {
@ -87,9 +87,8 @@ export function create<State, DraftApi>(options: Options<State, DraftApi>): Inte
})
const apply = (transform: TransformCallback<DraftApi>, draft: DraftApi) =>
Effect.suspend(() => {
const result = transform(draft)
return Effect.isEffect(result) ? Effect.asVoid(result).pipe(Effect.orDie) : Effect.void
Effect.sync(() => {
transform(draft)
})
const materialize = Effect.fnUntraced(function* () {