From 5746f9522532bfacb5cfbb76a67221e4cdd90556 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 29 Apr 2022 20:05:39 +0800 Subject: [PATCH] minor refactor --- .../docusaurus-theme-classic/src/nprogress.ts | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/nprogress.ts b/packages/docusaurus-theme-classic/src/nprogress.ts index 4202032b33a5..9db730401d2e 100644 --- a/packages/docusaurus-theme-classic/src/nprogress.ts +++ b/packages/docusaurus-theme-classic/src/nprogress.ts @@ -7,28 +7,25 @@ import nprogress from 'nprogress'; import './nprogress.css'; -import type {Location} from 'history'; +import type {ClientModule} from '@docusaurus/types'; nprogress.configure({showSpinner: false}); const delay = 200; -export function onRouteUpdate({ - location, - previousLocation, -}: { - location: Location; - previousLocation: Location | null; -}): (() => void) | undefined { - if (location.pathname !== previousLocation?.pathname) { - const progressBarTimeout = window.setTimeout(() => { - nprogress.start(); - }, delay); - return () => window.clearTimeout(progressBarTimeout); - } - return undefined; -} +const clientModule: ClientModule = { + onRouteUpdate({location, previousLocation}) { + if (location.pathname !== previousLocation?.pathname) { + const progressBarTimeout = window.setTimeout(() => { + nprogress.start(); + }, delay); + return () => window.clearTimeout(progressBarTimeout); + } + return undefined; + }, + onRouteDidUpdate() { + nprogress.done(); + }, +}; -export function onRouteDidUpdate(): void { - nprogress.done(); -} +export default clientModule;