Skip to content

Commit

Permalink
feat(plugin-content-update): 新增内容更新触发类型
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Dec 30, 2023
1 parent d537d5a commit 85b6d2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const Content = defineComponent({
return () =>
pageComponent.value
? h(pageComponent.value, {
onVnodeMounted: runCallbacks,
onVnodeUpdated: runCallbacks,
onVnodeBeforeUnmount: runCallbacks,
onVnodeMounted: () => runCallbacks({ mounted: true }),
onVnodeUpdated: () => runCallbacks({ updated: true }),
onVnodeBeforeUnmount: () => runCallbacks({ beforeUnmount: true }),
})
: h(
'div',
Expand Down
13 changes: 9 additions & 4 deletions plugins/plugin-content-update/src/client/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { onUnmounted } from 'vue'

// eslint-disable-next-line import/no-mutable-exports
export let contentUpdatedCallbacks: (() => any)[] = []
export interface ContentUpdated {
mounted?: boolean
updated?: boolean
beforeUnmount?: boolean
}

let contentUpdatedCallbacks: ((lifeCircleType: ContentUpdated) => any)[] = []

/**
* Register callback that is called every time the markdown content is updated
Expand All @@ -14,6 +19,6 @@ export function onContentUpdated(fn: () => any) {
})
}

export function runCallbacks() {
contentUpdatedCallbacks.forEach(fn => fn())
export function runCallbacks(lifeCircleType: ContentUpdated) {
contentUpdatedCallbacks.forEach(fn => fn(lifeCircleType))
}

0 comments on commit 85b6d2c

Please sign in to comment.