Skip to content

Commit

Permalink
Add undocumented preview function
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes committed Feb 15, 2024
1 parent c8bb4b6 commit 55c9d31
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type OnChange = (state: State) => void
interface InternalInstance {
back(): void
go(path: string, options?: { replace: boolean }): void
preview(path: string): string
onChange: OnChange
get(): State
end(): void
Expand Down Expand Up @@ -87,6 +88,10 @@ function Superhistory({
})
}

function preview(path: string): string {
return path
}

function back() {
_window.history.back()
}
Expand Down Expand Up @@ -125,7 +130,7 @@ function Superhistory({
return child
}

return { go, end, back, get, prefix, child, onChange }
return { go, end, back, get, preview, prefix, child, onChange }
}

function SuperhistoryChild({
Expand Down Expand Up @@ -164,6 +169,11 @@ function SuperhistoryChild({
reportChanges()
}

function preview(path: string, options: { replace?: boolean } = {}) {
path = normalizePath(path)
return joinPath(_prefix, path)
}

function get() {
const rootPath = _window.location.pathname
const i = rootPath.indexOf(_prefix)
Expand Down Expand Up @@ -196,7 +206,7 @@ function SuperhistoryChild({
return child
}

const self = { go, end, back, get, prefix, child, onChange }
const self = { go, end, back, get, prefix, child, onChange, preview }
return self
}

Expand Down

0 comments on commit 55c9d31

Please sign in to comment.