| 41 | |
| 42 | /** @internal */ |
| 43 | const findAncestor = ( |
| 44 | _ref: FiberRef.FiberRef<any>, |
| 45 | _parentStack: ReadonlyArray<readonly [FiberId.Single, unknown]>, |
| 46 | _childStack: ReadonlyArray<readonly [FiberId.Single, unknown]>, |
| 47 | _childModified = false |
| 48 | ): readonly [unknown, boolean] => { |
| 49 | const ref = _ref |
| 50 | let parentStack = _parentStack |
| 51 | let childStack = _childStack |
| 52 | let childModified = _childModified |
| 53 | let ret: readonly [unknown, boolean] | undefined = undefined |
| 54 | while (ret === undefined) { |
| 55 | if (Arr.isNonEmptyReadonlyArray(parentStack) && Arr.isNonEmptyReadonlyArray(childStack)) { |
| 56 | const parentFiberId = Arr.headNonEmpty(parentStack)[0] |
| 57 | const parentAncestors = Arr.tailNonEmpty(parentStack) |
| 58 | const childFiberId = Arr.headNonEmpty(childStack)[0] |
| 59 | const childRefValue = Arr.headNonEmpty(childStack)[1] |
| 60 | const childAncestors = Arr.tailNonEmpty(childStack) |
| 61 | if (parentFiberId.startTimeMillis < childFiberId.startTimeMillis) { |
| 62 | childStack = childAncestors |
| 63 | childModified = true |
| 64 | } else if (parentFiberId.startTimeMillis > childFiberId.startTimeMillis) { |
| 65 | parentStack = parentAncestors |
| 66 | } else { |
| 67 | if (parentFiberId.id < childFiberId.id) { |
| 68 | childStack = childAncestors |
| 69 | childModified = true |
| 70 | } else if (parentFiberId.id > childFiberId.id) { |
| 71 | parentStack = parentAncestors |
| 72 | } else { |
| 73 | ret = [childRefValue, childModified] as const |
| 74 | } |
| 75 | } |
| 76 | } else { |
| 77 | ret = [ref.initial, true] as const |
| 78 | } |
| 79 | } |
| 80 | return ret |
| 81 | } |
| 82 | |
| 83 | /** @internal */ |
| 84 | export const joinAs = dual< |