Skip to content

Commit

Permalink
Rename so path = global to align with superouter
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes committed Apr 27, 2024
1 parent b9ff6b7 commit f6cd1ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/index.ts
Expand Up @@ -13,7 +13,7 @@ export type _History = {
back(): void
}

export type State = { path?: string, fullPath?: string }
export type State = { path?: string, localPath?: string }

export type OnChange = (state: State) => void

Expand Down Expand Up @@ -121,7 +121,7 @@ function Superhistory({
const path = normalizePath(_window.location.pathname)
return {
path,
fullPath: path
localPath: path
}
}

Expand Down Expand Up @@ -201,7 +201,7 @@ function SuperhistoryChild({
reportChanges()
}

function preview(path: string, options: { replace?: boolean } = {}) {
function preview(path: string, _: { replace?: boolean } = {}) {
path = normalizePath(path)
return joinPath(_prefix, path)
}
Expand All @@ -211,8 +211,8 @@ function SuperhistoryChild({
const i = rootPath.indexOf(_prefix)
const child = i == -1 ? undefined : rootPath.slice(i+_prefix.length)
return {
path: child != null ? normalizePath(child) : child,
fullPath: child != null ? joinPath(_prefix, child) : child
localPath: child != null ? normalizePath(child) : child,
path: child != null ? joinPath(_prefix, child) : child
}
}

Expand Down
22 changes: 12 additions & 10 deletions readme.md
Expand Up @@ -2,6 +2,8 @@

A tiny history API with nested contexts.

> This is being iterated on quite often, expect breaking changes for a while.
## Example

Check out this example on [flems](https://flems.io/#0=N4IgZglgNgpgziAXAbVAOwIYFsZJAOgAsAXLKEAGhAGMB7NYmBvEAXwvW10QICsEqdBk2J4IWAA60ATsQAEWCnOBzqcOErqT6IuRjiq5rOWGm0scgOQliEuIgD0D+FnxxCDgEYZqxDAAEABnwATnwARgAmSwAdNHEpWTkAKj0Db18MEzMLa2JbeycXNw8MvyDQiOi4hJl5AGUAVwkYaUIIOGIZAE9s8ysbO0dnOFd3Bzhm1vbOnorgwIBaNBgAD2IIgFZYtDihTrlPWmhWiSgMRjkAXlV1AAM4uTkSMiUjgBNupUJw78j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O13Hf3A6UFRg6LmbK-T6FC2Tqx4dRUTVfayxC6LtdNGzUamBzsOY1afPOxrzue1L70lFHsfQ+r+OZ5DpOaxT1GDXb6ex+7kbs43mfpvDoe5oLomsAwVFM0YkQ04X-dNMaSTd5vuQKGQR+n6sTGlEsaIv4Ba-3-3AAXTfgvfAp8JB+hATfWsnY5DIFWJpG8xlLAAElGC5DkAAajkKsIMwD54AM5PNQh6cwEk0gQQkh8I-TIGFJoS+DBAH7SgU-ImGB-5UPTtgv0HdOELxmpWQseoYBA2FB2K4NwBHyWIIpfAYB75QAAAoqV4Xwhe40rCJl8BAZUMB16ULUTOFO+jDGd2IaYrudMDEWKXFo-SujVwWM7gLdEEgWxnBgGFJx9prFqJ9t4kOjsAmLkIPXdEAiqzCNEe8cxwTyb0GoDeXmfoYBBiCXEmcMBBEwF0QwAAIkWHCUAZGxIyfCKRsMxEsMIV7OJ7BVAMOIKUwxzTOGtMIe0p+tT36dM9r0+E3S5DmLUnNMGaBXBYF8gwP0npqCkREPgD4Xw5CbQkEGSgIBrSwG0YZPA4RwjAkQJsYEbAOAgEwDgPAmZ1AbL-CIFgrBAGsCAA)
Expand All @@ -28,33 +30,33 @@ A.get()
A.go('/a/b/c/d/e')
A.go('/a/b/c/d/e/f', { replace: true })
A.get()
// { path: 'a/b/c/d/e/f', fullPath: '/a/b/c/d/e/f' }
// { path: '/a/b/c/d/e/f', localPath: '/a/b/c/d/e/f' }
A.back()
A.get()
// { path: 'a/b/c/d', fullPath: '/a/b/c/d' }
// { path: '/a/b/c/d', localPath: '/a/b/c/d' }


const B = A.get('/a/b')
const C = B.get('/c')

B.get()
// { path: '/c/d', fullPath: '/a/b/c/d' }
// { localPath: '/c/d', path: '/a/b/c/d' }

C.get()
// { path: '/d', fullPath: '/a/b/c/d' }
// { localPath: '/d', path: '/a/b/c/d' }

C.go('/g')
;[C.get(), B.get(), A.get()]
// [
// { path: '/g', fullPath: '/a/b/c/g' },
// { path: '/c/g', fullPath: '/a/b/c/g' } ,
// { path: '/a/b/c/g', fullPath: '/a/b/c/g' }
// { localPath: '/g', path: '/a/b/c/g' },
// { localPath: '/c/g', path: '/a/b/c/g' } ,
// { localPath: '/a/b/c/g', path: '/a/b/c/g' }
// ]

C.preview('/h')
// 'a/b/c/h'
C.get()
// { path: '/a/b/c/g', fullPath: '/a/b/c/g' }
// { localPath: '/a/b/c/g', path: '/a/b/c/g' }
```

## API
Expand All @@ -79,13 +81,13 @@ The `_window` parameter there is available as an override for serverside usage o
```typescript
type State = {
path: string | undefined,
fullPath: string | undefined
localPath: string | undefined
}

instance.get(): State
```

Returns the instance's `path` in its local context and the `fullPath`. Returns `undefined` for both properties if a nested history is not compatible with the current browser location pathname.
Returns the instance's `localPath` in its local context and the global `path`. Returns `undefined` for both properties if a nested history is not compatible with the current browser location pathname.

### `instance.preview(path: string): string`

Expand Down

0 comments on commit f6cd1ec

Please sign in to comment.