Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed Nov 7, 2019
1 parent 0113921 commit c679f16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ export function useEffect (cb, deps) {
if (isChanged(hook[1], deps)) {
hook[0] = useCallback(cb, deps)
hook[1] = deps
currentHook.hooks.effects.push(hook)
currentHook.hooks.effect.push(hook)
}
}

export function useMemo (cb, deps) {
let hook = getHook(cursor++)

if (isChanged(hook[1], deps)) {
hook[1] = deps
return (hook[0] = cb())
Expand All @@ -55,7 +54,7 @@ export function useRef (current) {
}

export function getHook (cursor) {
let hooks = currentHook.hooks || (currentHook.hooks = { list: [], effects: [], cleans: [] })
let hooks = currentHook.hooks || (currentHook.hooks = { list: [], effect: [], cleanup: [] })
if (cursor >= hooks.list.length) {
hooks.list.push([])
}
Expand Down
28 changes: 13 additions & 15 deletions src/reconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,6 @@ function commit (fiber) {
}
}


function defer (fiber) {
requestAnimationFrame(() => {
if (fiber.hooks) {
fiber.hooks.cleans.forEach(c => c())
fiber.hooks.cleans = []
fiber.hooks.effects.forEach((e, i) => {
const clean = e[0]()
if (clean) fiber.hooks.cleans[i] = clean
})
fiber.hooks.effects = []
}
})
}

function createFiber (vnode, op) {
return { ...vnode, op, tag: isFn(vnode.type) ? HOOK : HOST }
}
Expand All @@ -233,3 +218,16 @@ function hashfy (arr) {
}

export const isFn = fn => typeof fn === 'function'

function defer (fiber) {
requestAnimationFrame(() => {
if (fiber.hooks) {
fiber.hooks.cleanup.forEach(c => c())
fiber.hooks.effect.forEach((e, i) => {
const res = e[0]()
if (res) fiber.hooks.cleanup[i] = res
})
fiber.hooks.effect = []
}
})
}

0 comments on commit c679f16

Please sign in to comment.