WritesCheck.verify
function · packages/surface/src/writesCheck.ts:142
verify<
Root,
Message,
Return extends {
readonly model: Root
},
>(
writes: {
readonly declared: (message: Message) => Option.Option<DependencyTree>
},
update: (model: Root, message: Message) => Return,
options?: {
readonly surfaces?: ClosedSurfaces<Root>
readonly contracts?: ReadonlyArray<OwnershipContract>
readonly report?: (diagnostic: WriteDiagnostic) => void
},
): (model: Root, message: Message) => Returnupdate, checked after every Message that changes the Model: a path that
changed outside the writes its transition declares is an UndeclaredWrite,
and a closed Surface in surfaces changed by a Message outside its
messages is an OutsideWrite. A Message with no transition is checked
against the closed Surfaces alone. Each finding goes to report.
It walks the Model on every Message, so reach it only in development, which also leaves it out of a production build:
Example
const update = writes.track(
import.meta.env.DEV ? WritesCheck.verify(writes, appUpdate, { surfaces: [Header] }) : appUpdate,
)