Skip to content

Commit

Permalink
计算属性新增 out 配置
Browse files Browse the repository at this point in the history
  • Loading branch information
musicode committed Sep 26, 2022
1 parent 1aa76c7 commit 20f3e34
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions src/Yox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,32 +563,6 @@ export default class Yox implements YoxInterface {

if (process.env.NODE_ENV !== 'pure') {

const { slots } = $options
if (slots) {
for (let name in slots) {
observer.addComputed(
name,
{
get: slots[name],
args: [instance],
}
)
}
}

observer.addComputed(
templateComputed,
{
get: instance.render,
sync: constant.FALSE,
}
)

observer.watch(
templateComputed,
templateComputedWatcher
)

let placeholder: Node | void = constant.UNDEFINED,

{
Expand All @@ -598,6 +572,7 @@ export default class Yox implements YoxInterface {
context,
replace,
template,
slots,
transitions,
components,
directives,
Expand Down Expand Up @@ -674,6 +649,34 @@ export default class Yox implements YoxInterface {
observer.watch(watchers)
}

if (slots) {
for (let name in slots) {
observer.addComputed(
name,
{
get: slots[name],
args: [instance],
out(vnodes) {
return vnodes.map(snabbdom.clone)
},
}
)
}
}

observer.addComputed(
templateComputed,
{
get: instance.render,
sync: constant.FALSE,
}
)

observer.watch(
templateComputed,
templateComputedWatcher
)

if (process.env.NODE_ENV !== 'pure') {
const afterCreateHook = $options[HOOK_AFTER_CREATE]
if (afterCreateHook) {
Expand Down Expand Up @@ -1325,12 +1328,11 @@ export default class Yox implements YoxInterface {
HOOK_BEFORE_DESTROY
)

const { $vnode } = instance

if ($parent && $parent.$children) {
array.remove($parent.$children, instance)
}

const { $vnode } = instance
if ($vnode) {
snabbdom.destroy(domApi, $vnode, !$parent)
}
Expand Down

0 comments on commit 20f3e34

Please sign in to comment.