Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed May 26, 2023
1 parent a3a8b3f commit 9135ca8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
10 changes: 3 additions & 7 deletions src/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@ import { IFiber, IRef } from './type'
import { updateElement } from './dom'
import { isFn, TAG } from './reconcile'

export const commit = (fiber: IFiber, deletions): void => {
export const commit = (fiber: IFiber): void => {
commitWork(fiber)
deletions.forEach(commitWork)
}

const commitWork = (fiber: any) => {
if (!fiber) {
return
}

const { op, before, elm } = fiber.action || {}

if (op === TAG.REMOVE) {
remove(fiber)
return
}
if (op & TAG.INSERT || op & TAG.MOVE) {
if (fiber.isComp) {
fiber.child.lane = fiber.lane
fiber.child.action = fiber.action
} else {
fiber.parentNode.insertBefore(elm.node, before?.node)
}
}
if (op & TAG.UPDATE) {
if (fiber.isComp) {
fiber.child.lane = fiber.lane
fiber.child.action = fiber.action
} else {
updateElement(fiber.node, fiber.oldProps || {}, fiber.props)
}
Expand Down Expand Up @@ -59,5 +56,4 @@ const remove = fiber => {
kidsRefer(fiber.kids)
refer(fiber.ref, null)
}
fiber.lane = 0
}
3 changes: 1 addition & 2 deletions src/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { isArr, createText } from './h'
import { commit } from './commit'

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

export const enum TAG {
Expand Down Expand Up @@ -42,7 +41,7 @@ export const update = (fiber?: IFiber) => {
const reconcile = (fiber?: IFiber): boolean => {
while (fiber && !shouldYield()) fiber = capture(fiber)
if (fiber) return reconcile.bind(null, fiber)
commit(rootFiber, deletions)
commit(rootFiber)
return null
}

Expand Down
6 changes: 1 addition & 5 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export interface IFiber<P extends Attributes = any> {
key?: string
type: string | FC<P>
parentNode: HTMLElementEx
childNodes: any
node: HTMLElementEx
kids?: any
parent?: IFiber<P>
Expand All @@ -54,12 +53,9 @@ export interface IFiber<P extends Attributes = any> {
ref: IRef
hooks: IHook
oldProps: P
after: any
action: any
props: P
lane: number
time: number
next: IFiber
dirty: boolean
isComp: boolean
}

Expand Down

0 comments on commit 9135ca8

Please sign in to comment.