-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): add
onContentUpdated
hooks
- Loading branch information
1 parent
82379c0
commit a2f17b1
Showing
3 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { onUnmounted } from 'vue' | ||
|
||
let contentUpdatedCallbacks: (() => unknown)[] = [] | ||
|
||
/** | ||
* Register callback that is called every time the markdown content is updated | ||
* in the DOM. | ||
*/ | ||
export const onContentUpdated = (fn: () => unknown): void => { | ||
contentUpdatedCallbacks.push(fn) | ||
onUnmounted(() => { | ||
contentUpdatedCallbacks = contentUpdatedCallbacks.filter((f) => f !== fn) | ||
}) | ||
} | ||
|
||
/** | ||
* Call all registered callbacks | ||
*/ | ||
export const runCallbacks = (): void => { | ||
contentUpdatedCallbacks.forEach((fn) => fn()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './clientData.js' | ||
export * from './clientDataUtils.js' | ||
export * from './updateHead.js' | ||
export * from './contentUpdated.js' |