Skip to content

Commit

Permalink
re add getPaused setPaused
Browse files Browse the repository at this point in the history
  • Loading branch information
willybrauner committed Jan 9, 2024
1 parent d4735e9 commit de0383d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export interface IRouterContext extends IRouterContextStackStates {
routeIndex: number
previousPageIsMount: boolean
unmountPreviousPage: () => void
getPaused: () => boolean
setPaused: (value: boolean) => void
}

// -------------------------------------------------------------------------------- PREPARE / CONTEXT
Expand All @@ -85,6 +87,8 @@ export const RouterContext = createContext<IRouterContext>({
previousPageIsMount: true,
staticLocation: undefined,
unmountPreviousPage: () => {},
getPaused: () => false,
setPaused: (value: boolean) => {},
})
RouterContext.displayName = "RouterContext"

Expand Down Expand Up @@ -245,13 +249,31 @@ function Router(props: {

const currentRouteRef = useRef<TRoute>()

/**
* Enable paused on Router instance
*/
const _waitingUrl = useRef(null)
const _paused = useRef<boolean>(false)
const getPaused = () => _paused.current
const setPaused = (value: boolean) => {
_paused.current = value
if (!value && _waitingUrl.current) {
handleHistory(_waitingUrl.current)
_waitingUrl.current = null
}
}
/**
* Handle history
* Update routes when history change
* Dispatch new routes via RouterContext
*/

const handleHistory = async (url = ""): Promise<void> => {
if (_paused.current) {
_waitingUrl.current = url
return
}

const matchingRoute = getRouteFromUrl({
pUrl: url,
pRoutes: routes,
Expand Down Expand Up @@ -411,6 +433,8 @@ function Router(props: {
routeIndex,
previousPageIsMount,
unmountPreviousPage,
getPaused,
setPaused,
}}
/>
)
Expand Down

0 comments on commit de0383d

Please sign in to comment.