MCPcopy Create free account
hub / github.com/effect-app/libs / structuralShare

Function structuralShare

packages/vue/src/atomQuery.ts:171–183  ·  view source on GitHub ↗
(
  self: Atom.Atom<AsyncResult.AsyncResult<A, E>>
)

Source from the content-addressed store, hash-verified

169 */
170export const replaceEqualDeep = (prev: any, next: any): any => {
171 if (prev === next) return prev
172 const bothArrays = Array.isArray(prev) && Array.isArray(next)
173 if (bothArrays || (isPlainObject(prev) && isPlainObject(next))) {
174 const a: Record<PropertyKey, any> = prev
175 const b: Record<PropertyKey, any> = next
176 const copy: Record<PropertyKey, any> = bothArrays ? [] : {}
177 const nextKeys: Array<PropertyKey> = bothArrays ? (b as Array<any>).map((_, i) => i) : Object.keys(b)
178 const nextSize = nextKeys.length
179 const prevSize = bothArrays ? (a as Array<any>).length : Object.keys(a).length
180 let equalItems = 0
181 for (let i = 0; i < nextSize; i++) {
182 const key = nextKeys[i]!
183 copy[key] = replaceEqualDeep(a[key], b[key])
184 if (copy[key] === a[key] && a[key] !== undefined) equalItems++
185 }
186 return prevSize === nextSize && equalItems === prevSize ? prev : copy

Callers 1

withQueryOptionsFunction · 0.85

Calls 4

replaceEqualDeepFunction · 0.85
selfMethod · 0.80
getFunction · 0.70
transformMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…