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

Function patchElement

packages/effect/src/ui/internal/kernel.ts:1997–2063  ·  view source on GitHub ↗
(
  inst: Instance,
  rec: Rec,
  prev: View.Element<any, any>,
  view: View.Element<any, any>
)

Source from the content-addressed store, hash-verified

1995}
1996
1997const patchElement = (
1998 inst: Instance,
1999 rec: Rec,
2000 prev: View.Element<any, any>,
2001 view: View.Element<any, any>
2002): void => {
2003 const host = inst.tree.host
2004 const node = rec.node
2005 const layers = view.owned?.length ? view.owned : prev.owned
2006 if (layers?.length) view = owned(inst, view, layers)
2007 rec.v = view
2008 rec.plain = false
2009 if (prev.attrs !== view.attrs) patchAttrs(host, node, prev.attrs, view.attrs)
2010 if (
2011 view.handlers !== prev.handlers || view.eventOptions !== prev.eventOptions
2012 ) {
2013 host.setEvents(
2014 node,
2015 rec,
2016 prev.handlers === View.noFields && prev.eventOptions === View.noFields
2017 )
2018 }
2019 const views = view.children
2020 const olds = rec.kids
2021 if (dev && views.length > 1) checkKeys(inst.path, views)
2022 if (olds === undefined) {
2023 if (views.length > 0) {
2024 const kids: Array<Rec> = new Array(views.length)
2025 for (let index = 0; index < views.length; index++) {
2026 place(host, node, kids[index] = create(inst, views[index]!, node), null)
2027 }
2028 rec.kids = kids
2029 }
2030 } else if (views.length === 0) {
2031 removeAll(inst, node, olds)
2032 rec.kids = undefined
2033 } else if (views.length === 1 && olds.length === 1) {
2034 const old = olds[0]!
2035 const next = views[0]!
2036 if (next._tag === "Text" && old.v._tag === "Text") {
2037 if (old.v.text !== next.text) host.setText(old.node, next.text)
2038 old.v = next
2039 } else if (
2040 next._tag === "Element" && old.v !== next && pairs(old.v, next)
2041 ) {
2042 patchElement(inst, old, old.v as View.Element<any, any>, next)
2043 } else olds[0] = patch(inst, old, next)
2044 } else rec.kids = patchList(inst, node, olds, views, null, true)
2045 // After the children, so a select's value wins over its options'.
2046 if (
2047 prev.props !== view.props ||
2048 (host.controlled !== undefined && view.props !== View.noFields)
2049 ) {
2050 patchProps(host, node, prev.props, view.props)
2051 }
2052 const mount = view.mount as unknown as Attachable | undefined
2053 const was = prev.mount as unknown as Attachable | undefined
2054 if (mount !== was) {

Callers 1

patchFunction · 0.85

Calls 12

checkKeysFunction · 0.90
patchAttrsFunction · 0.85
removeAllFunction · 0.85
patchListFunction · 0.85
patchPropsFunction · 0.85
setEventsMethod · 0.80
setTextMethod · 0.80
ownedFunction · 0.70
placeFunction · 0.70
createFunction · 0.70
pairsFunction · 0.70
patchFunction · 0.70

Tested by

no test coverage detected