Skip to content

Commit

Permalink
调整模板渲染时机
Browse files Browse the repository at this point in the history
  • Loading branch information
musicode committed Sep 28, 2022
1 parent 20f3e34 commit 0dc3d85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
Binary file added dist/.DS_Store
Binary file not shown.
37 changes: 16 additions & 21 deletions src/Yox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,19 @@ compileTemplate = cache.createOneKeyCache(
templateComputed = '$$template',

templateComputedWatcher = {
watcher() {
this.$isDirty = constant.TRUE
watcher(vnode: VNode) {
this.update(
vnode,
this.$vnode as VNode
)
},
sync: constant.TRUE,
},

outputSlot = function (vnodes: VNode[] | void) {
return vnodes
? vnodes.map(snabbdom.clone)
: vnodes
}

export default class Yox implements YoxInterface {
Expand Down Expand Up @@ -181,8 +190,6 @@ export default class Yox implements YoxInterface {

private $filters?: Record<string, Filter>

private $isDirty?: boolean

/**
* core 版本
*/
Expand Down Expand Up @@ -503,17 +510,7 @@ export default class Yox implements YoxInterface {
const observer = instance.$observer = new Observer(
source,
instance,
instance.$nextTask = new NextTask({
afterTask() {
if (instance.$isDirty) {
instance.$isDirty = constant.UNDEFINED
instance.update(
instance.get(templateComputed) as VNode,
instance.$vnode as VNode
)
}
}
})
instance.$nextTask = new NextTask()
)

if (computed) {
Expand Down Expand Up @@ -572,11 +569,11 @@ export default class Yox implements YoxInterface {
context,
replace,
template,
slots,
transitions,
components,
directives,
filters,
slots,
} = $options

if (model) {
Expand Down Expand Up @@ -655,10 +652,8 @@ export default class Yox implements YoxInterface {
name,
{
get: slots[name],
args: [instance],
out(vnodes) {
return vnodes.map(snabbdom.clone)
},
input: [instance],
output: outputSlot,
}
)
}
Expand Down Expand Up @@ -1212,7 +1207,7 @@ export default class Yox implements YoxInterface {
// 其他情况不为空
const { current } = Computed
if (current) {
current.addDep($observer, keypath)
current.addDynamicDep($observer, keypath)
}
}
)
Expand Down

0 comments on commit 0dc3d85

Please sign in to comment.