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

Function forwardTo

packages/effect/src/ui/View.ts:715–737  ·  view source on GitHub ↗
(
  builder: ElementBuilder<Msg, any, any, any>,
  hooks: ReadonlyArray<Forward>,
  content: ReadonlyArray<Node<Msg, any>>
)

Source from the content-addressed store, hash-verified

713// goes on what the hook returns, as siblings are matched by the outermost
714// node.
715const forwardTo = <Msg, R>(
716 builder: ElementBuilder<Msg, any, any, any>,
717 hooks: ReadonlyArray<Forward>,
718 content: ReadonlyArray<Node<Msg, any>>
719): Element<Msg, R> => {
720 const finished = copyBuilder(builder) as Mutable<
721 ElementBuilder<Msg, any, any, any>
722 >
723 finished.hooks = hooks.length === 1 ? undefined : hooks.slice(0, -1)
724 finished.content = content
725 finished.elementKey = undefined
726 const hook: PartForward = hooks[hooks.length - 1]!
727 finished[partForwardLayer] = hook[partForwardLayer]
728 const out: Node<Msg, R> = toNode(hook(finished))
729 if (out._tag !== "Element") {
730 throw new Error(
731 `forward: the <${builder.tag}> was built into a ${out._tag}, and its hook has to return an element`
732 )
733 }
734 return builder.elementKey === undefined
735 ? out
736 : { ...out, elementKey: builder.elementKey }
737}
738
739/**
740 * A copy of `builder` with `place` added after the hooks it already holds.

Callers 1

buildWithFunction · 0.85

Calls 4

copyBuilderFunction · 0.85
toNodeFunction · 0.85
hookFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected