Skip to content

Commit

Permalink
refactor: 💡 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
WeilinerL committed Nov 22, 2024
1 parent aeb2251 commit be8405e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/website/lib/iframe-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const syncPathToParent = (iframe: HTMLIFrameElement, to: string) => {
* @returns
*/
export const onPathchange = (callback?: (path: string) => void): () => void => {
const cache = { prevPath: '' }
let prevPath = ''
const handleMessage = (e: { data: { value: string } }) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { value } = (typeof e.data === 'object' ? e.data || {} : {})
if (value !== undefined && value !== cache.prevPath) {
if (value !== undefined && value !== prevPath) {
callback?.(value)
cache.prevPath = value
prevPath = value
}
}
window.addEventListener('message', handleMessage)
Expand Down

0 comments on commit be8405e

Please sign in to comment.