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

Function pushChild

packages/effect/src/ui/View.ts:558–581  ·  view source on GitHub ↗
(
  out: Array<Node<Msg, any>>,
  input: Content<Msg, any> | string | false | null | undefined
)

Source from the content-addressed store, hash-verified

556}
557
558const pushChild = <Msg>(
559 out: Array<Node<Msg, any>>,
560 input: Content<Msg, any> | string | false | null | undefined
561): void => {
562 if (input === false || input === null || input === undefined) return
563 if (typeof input === "string") {
564 if (input === "") return
565 const last = out.length === 0 ? undefined : out[out.length - 1]
566 if (last !== undefined && last._tag === "Text") {
567 out[out.length - 1] = text(last.text + input)
568 } else out.push(text(input))
569 return
570 }
571 const node: Node<Msg, any> = toNode(input)
572 if (node._tag === "Text") {
573 if (node.text === "") return
574 const last = out.length === 0 ? undefined : out[out.length - 1]
575 if (last !== undefined && last._tag === "Text") {
576 out[out.length - 1] = text(last.text + node.text)
577 return
578 }
579 }
580 out.push(node)
581}
582
583/**
584 * Whether a value is an element builder.

Callers 1

childrenFunction · 0.85

Calls 3

toNodeFunction · 0.85
textFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected