Skip to content

Commit

Permalink
fix(doc): progress bar should not use unmount function
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed Nov 7, 2021
1 parent f580f43 commit 0587103
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/varlet-cli/site/useProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function useProgress() {
currentThemes = themes
props.trackColor = getTrackColor(themes)
props.color = props.value === 100 ? getTrackColor(themes) : getColor(themes)
})
}, false)

const changeValue = () => {
timer = window.setTimeout(() => {
Expand Down
21 changes: 12 additions & 9 deletions packages/varlet-cli/site/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function getPCLocationInfo(): PCLocationInfo {

return {
language,
menuName
menuName,
}
}

Expand All @@ -50,7 +50,7 @@ export function isPhone() {
export enum MenuTypes {
TITLE = 1,
COMPONENT = 2,
DOCUMENTATION = 3
DOCUMENTATION = 3,
}

export function inIframe() {
Expand All @@ -74,9 +74,7 @@ export function getHashSearch() {

export function watchLang(cb: (lang: string) => void, platform: 'pc' | 'mobile' = 'mobile') {
const handleHashchange = () => {
const language = platform === 'mobile'
? (getHashSearch().get('language') ?? 'zh-CN')
: getPCLocationInfo().language
const language = platform === 'mobile' ? getHashSearch().get('language') ?? 'zh-CN' : getPCLocationInfo().language

cb(language)
}
Expand All @@ -97,7 +95,10 @@ export function watchPlatform(cb: (platform: string) => void) {
handleHashchange()
}

export function watchThemes(cb: (themes: 'themes' | 'darkThemes', from: 'pc' | 'mobile' | 'default') => void) {
export function watchThemes(
cb: (themes: 'themes' | 'darkThemes', from: 'pc' | 'mobile' | 'default') => void,
shouldUnmount = true
) {
const handleThemesChange = (event: MessageEvent) => {
const { data } = event
if (data.action === 'themesChange') {
Expand All @@ -107,9 +108,11 @@ export function watchThemes(cb: (themes: 'themes' | 'darkThemes', from: 'pc' | '

window.addEventListener('message', handleThemesChange)

onUnmounted(() => {
window.removeEventListener('message', handleThemesChange)
})
if (shouldUnmount) {
onUnmounted(() => {
window.removeEventListener('message', handleThemesChange)
})
}

cb(getBrowserThemes(), 'default')
}
Expand Down

0 comments on commit 0587103

Please sign in to comment.