Skip to content

Commit

Permalink
root update
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed May 26, 2023
1 parent 5092891 commit c0e5b3d
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { isArr, createText } from './h'
import { commit } from './commit'

let currentFiber: IFiber = null
let effectList: IFiber = null
let deletions: any = []
let rootFiber = null

export const enum TAG {
UPDATE = 1 << 1,
Expand All @@ -28,26 +28,21 @@ export const enum TAG {
}

export const render = (vnode: FreElement, node: Node): void => {
const rootFiber = {
rootFiber = {
node,
props: { children: vnode },
} as IFiber
update(rootFiber)
}

export const update = (fiber?: IFiber) => {
if (fiber && !(fiber.lane & TAG.DIRTY)) {
fiber.lane = TAG.UPDATE | TAG.DIRTY
schedule(() => {
effectList = fiber
return reconcile(fiber)
})
}
schedule(() => reconcile(fiber))
}

const reconcile = (fiber?: IFiber): boolean => {
while (fiber && !shouldYield()) fiber = capture(fiber)
if (fiber) return reconcile.bind(null, fiber)
commit(rootFiber, deletions)
return null
}

Expand Down Expand Up @@ -80,11 +75,6 @@ const capture = (fiber: IFiber): IFiber | undefined => {
const getSibling = (fiber) => {
while (fiber) {
bubble(fiber)
if (fiber.lane & TAG.DIRTY) {
fiber.lane &= ~TAG.DIRTY
commit(fiber, deletions)
return null
}
if (fiber.sibling) return fiber.sibling
fiber = fiber.parent
}
Expand Down Expand Up @@ -224,9 +214,6 @@ var diff1 = function (a, b) {
var extr = function (v) {
return v.key;
};
var replace = function (elm, i, newElm) {
actions.push({ op: 'replace', target: a[i], replacement: newElm })
};
var update = function (a, b) {
clone(a, b)
actions.push({ op: TAG.UPDATE, old: a, new: b })
Expand All @@ -245,7 +232,7 @@ var diff1 = function (a, b) {
old: a,
cur: b,
key: extr,
add, move, remove, replace, update
add, move, remove, update
});
return actions
}
Expand Down

0 comments on commit c0e5b3d

Please sign in to comment.