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

Function patchList

packages/effect/src/ui/internal/kernel.ts:2078–2189  ·  view source on GitHub ↗
(
  inst: Instance,
  parent: unknown,
  olds: Array<Rec>,
  views: ReadonlyArray<View.Node<any, any>>,
  after: unknown,
  whole?: boolean
)

Source from the content-addressed store, hash-verified

2076 : undefined
2077
2078const patchList = (
2079 inst: Instance,
2080 parent: unknown,
2081 olds: Array<Rec>,
2082 views: ReadonlyArray<View.Node<any, any>>,
2083 after: unknown,
2084 whole?: boolean
2085): Array<Rec> => {
2086 const host = inst.tree.host
2087 let start = 0
2088 let oldEnd = olds.length - 1
2089 let end = views.length - 1
2090 let out: Array<Rec> = oldEnd === end ? olds : new Array(views.length)
2091 while (
2092 start <= oldEnd && start <= end && pairs(olds[start]!.v, views[start]!)
2093 ) {
2094 out[start] = patch(inst, olds[start]!, views[start]!)
2095 start++
2096 }
2097 if (out === olds) {
2098 if (start > end) return out
2099 out = new Array(views.length)
2100 for (let index = 0; index < start; index++) out[index] = olds[index]!
2101 }
2102 while (
2103 start <= oldEnd && start <= end &&
2104 pairs(olds[oldEnd]!.v, views[end]!)
2105 ) {
2106 oldEnd--
2107 end--
2108 }
2109 const count = end - start + 1
2110 const sources = count > 0 && start <= oldEnd
2111 ? new Int32Array(count)
2112 : undefined
2113 let byKey: Map<unknown, number> | undefined
2114 let same: Int32Array | undefined
2115 for (let index = sources === undefined ? -1 : end; index >= start; index--) {
2116 const key = keyOf(views[index]!)
2117 if (key === undefined) continue
2118 const next = (byKey ??= new Map()).get(key)
2119 if (next !== undefined) {
2120 ;(same ??= new Int32Array(count))[index - start] = next + 1
2121 }
2122 byKey.set(key, index)
2123 }
2124 let moved = false
2125 let last = 0
2126 let gone: Array<Rec> | undefined
2127 for (let index = start; index <= oldEnd; index++) {
2128 const old = olds[index]!
2129 const key = keyOf(old.v)
2130 let to = key !== undefined
2131 ? byKey?.get(key)
2132 : index <= end
2133 ? index
2134 : undefined
2135 while (

Callers 2

refreshFunction · 0.85
patchElementFunction · 0.85

Calls 12

removeAllFunction · 0.85
nodeOfFunction · 0.85
increasingFunction · 0.85
pairsFunction · 0.70
patchFunction · 0.70
keyOfFunction · 0.70
createFunction · 0.70
removeFunction · 0.70
placeFunction · 0.70
getMethod · 0.65
setMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected