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

Function copyBuilder

packages/effect/src/ui/View.ts:927–944  ·  view source on GitHub ↗
(
  builder: B
)

Source from the content-addressed store, hash-verified

925 * much as the rest of building a view.
926 */
927const copyBuilder = <B extends ElementBuilder<any, any, any, any>>(
928 builder: B
929): B => {
930 // Counted in place: `Object.keys` would make an array for every copy.
931 let fields = 0
932 for (const _ in builder) fields++
933 if (fields === builderFields.length) {
934 const proto = Object.getPrototypeOf(builder)
935 let copier = proto === lastProto ? lastCopier : copiers.get(proto)
936 if (copier === undefined) {
937 copiers.set(proto, copier = makeCopier(proto, builder))
938 }
939 lastProto = proto
940 lastCopier = copier
941 if (copier !== null) return new copier(builder) as B
942 }
943 return Object.assign(Object.create(Object.getPrototypeOf(builder)), builder)
944}
945
946const builderFields = [
947 "elementKey",

Callers 10

forwardToFunction · 0.85
withForwardFunction · 0.85
withContentFunction · 0.85
withFieldsFunction · 0.85
eachOwnFunction · 0.85
keyMethod · 0.85
attrMethod · 0.85
attrsMethod · 0.85
propMethod · 0.85
propsMethod · 0.85

Calls 4

makeCopierFunction · 0.85
assignMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected