MCPcopy Create free account
hub / github.com/Effect-TS/effect / write

Function write

packages/effect/src/ui/internal/serialize.ts:242–361  ·  view source on GitHub ↗
(
  { late, tape }: Snapshot,
  query: unknown,
  ctx: Context.Context<any>,
  isStatic: boolean,
  to: services.ServerSink,
  rootKey?: string | undefined,
  props?: unknown,
  onUnencoded?: ((path: string, cause: Cause.Cause<SchemaIssue.Issue>) => void) | undefined
)

Source from the content-addressed store, hash-verified

240
241/** @internal */
242export const write = (
243 { late, tape }: Snapshot,
244 query: unknown,
245 ctx: Context.Context<any>,
246 isStatic: boolean,
247 to: services.ServerSink,
248 rootKey?: string | undefined,
249 props?: unknown,
250 onUnencoded?: ((path: string, cause: Cause.Cause<SchemaIssue.Issue>) => void) | undefined
251): Effect.Effect<Renderer.State> =>
252 Effect.map(awaitEncoded(late), () => {
253 const state: Record<string, unknown> = {}
254 let sink = to
255 /** Whether an instance above ships no state, so nothing below it does. */
256 let under = false
257 /** Saved state for nested ranges, fallbacks, and instances. */
258 const outer: Array<any> = []
259 const deferredPaths: Array<string> = []
260 const statuses: Record<string, string> = {}
261 const collected: Record<string, unknown> = {}
262 const ship = (path: string, status: Status) => {
263 if (status !== undefined) statuses[path] = status
264 }
265 for (let at = 0; at < tape.length;) {
266 const op = tape[at++]
267 const value = tape[at++]
268 switch (op) {
269 case Text:
270 sink.text(value)
271 break
272 case Open:
273 sink.open(value.tag, value.attrs, value.props)
274 break
275 case Close:
276 sink.close(value)
277 break
278 case Enter:
279 sink.enter(value)
280 outer.push(under)
281 break
282 case Leave:
283 sink.leave(value)
284 under = outer.pop()
285 break
286 case Fallback: {
287 const snap: FallbackSnap = value
288 if (!under) {
289 if (snap.failedChild) deferredPaths.push(snap.path)
290 else ship(snap.path, snap.status)
291 }
292 sink.enter(snap.path)
293 outer.push(under)
294 under = true
295 break
296 }
297 case Instance: {
298 const snap: InstanceSnap = value
299 const inst = snap.inst

Callers

nothing calls this directly

Calls 15

stateCodecOfFunction · 0.90
isRedactedFunction · 0.90
warnUnencodedFunction · 0.90
awaitEncodedFunction · 0.85
shipFunction · 0.85
encodedOfFunction · 0.85
warnRedactedFunction · 0.85
enterMethod · 0.80
keysMethod · 0.80
addFunction · 0.70
textMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected