Comparing version 0.10.0 to 0.10.2
import { Router } from './Router'; | ||
import { Params } from './URLTools'; | ||
import { Params, URLDescriptor } from './URLTools'; | ||
import { HTTPMethod } from './HTTPMethod'; | ||
export interface Env<Context extends object = any> { | ||
readonly context: Context; | ||
readonly hash: string; | ||
readonly mountname: string; | ||
readonly router: Router<Context>; | ||
readonly url: URLDescriptor; | ||
readonly body?: any; | ||
readonly headers: { | ||
[name: string]: string; | ||
}; | ||
readonly method: HTTPMethod; | ||
readonly params: Params; | ||
readonly pathname: string; | ||
readonly hash: string; | ||
readonly query: Params; | ||
readonly search: string; | ||
readonly router: Router<Context>; | ||
readonly unmatchedPathnamePart: string; | ||
} |
@@ -96,8 +96,11 @@ "use strict"; | ||
} | ||
var mountname = URLTools_1.joinPaths(env.mountname, matchedPathname); | ||
return { | ||
context: env.context, | ||
hash: env.hash, | ||
headers: env.headers, | ||
method: env.method, | ||
params: __assign({}, env.params, params), | ||
pathname: URLTools_1.joinPaths(env.pathname, matchedPathname), | ||
pathname: mountname, | ||
mountname: mountname, | ||
query: env.query, | ||
@@ -107,2 +110,3 @@ search: env.search, | ||
unmatchedPathnamePart: env.unmatchedPathnamePart.slice(matchedPathname.length) || (appendFinalSlash ? '/' : ''), | ||
url: env.url, | ||
}; | ||
@@ -109,0 +113,0 @@ } |
@@ -161,5 +161,7 @@ "use strict"; | ||
hash: '', | ||
headers: {}, | ||
method: HTTPMethod_1.HTTPMethod.Get, | ||
params: {}, | ||
pathname: '', | ||
mountname: '', | ||
query: url.query, | ||
@@ -169,2 +171,3 @@ search: url.search, | ||
unmatchedPathnamePart: url.pathname, | ||
url: url, | ||
}; | ||
@@ -171,0 +174,0 @@ var matchEnv = Mapping_1.matchMappingAgainstPathname(rootEnv, this.rootMapping, false); |
@@ -43,3 +43,5 @@ "use strict"; | ||
hash: url.hash, | ||
headers: {}, | ||
method: options.method || HTTPMethod_1.HTTPMethod.Get, | ||
mountname: '', | ||
params: url.query, | ||
@@ -50,2 +52,3 @@ pathname: '', | ||
router: this, | ||
url: url, | ||
unmatchedPathnamePart: url.pathname, | ||
@@ -52,0 +55,0 @@ }; |
import { Router } from './Router'; | ||
import { Params } from './URLTools'; | ||
import { Params, URLDescriptor } from './URLTools'; | ||
import { HTTPMethod } from './HTTPMethod'; | ||
export interface Env<Context extends object = any> { | ||
readonly context: Context; | ||
readonly hash: string; | ||
readonly mountname: string; | ||
readonly router: Router<Context>; | ||
readonly url: URLDescriptor; | ||
readonly body?: any; | ||
readonly headers: { | ||
[name: string]: string; | ||
}; | ||
readonly method: HTTPMethod; | ||
readonly params: Params; | ||
readonly pathname: string; | ||
readonly hash: string; | ||
readonly query: Params; | ||
readonly search: string; | ||
readonly router: Router<Context>; | ||
readonly unmatchedPathnamePart: string; | ||
} |
@@ -92,8 +92,11 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
var mountname = joinPaths(env.mountname, matchedPathname); | ||
return { | ||
context: env.context, | ||
hash: env.hash, | ||
headers: env.headers, | ||
method: env.method, | ||
params: __assign({}, env.params, params), | ||
pathname: joinPaths(env.pathname, matchedPathname), | ||
pathname: mountname, | ||
mountname: mountname, | ||
query: env.query, | ||
@@ -103,2 +106,3 @@ search: env.search, | ||
unmatchedPathnamePart: env.unmatchedPathnamePart.slice(matchedPathname.length) || (appendFinalSlash ? '/' : ''), | ||
url: env.url, | ||
}; | ||
@@ -105,0 +109,0 @@ } |
@@ -159,5 +159,7 @@ import { createURLDescriptor, joinPaths } from './URLTools'; | ||
hash: '', | ||
headers: {}, | ||
method: HTTPMethod.Get, | ||
params: {}, | ||
pathname: '', | ||
mountname: '', | ||
query: url.query, | ||
@@ -167,2 +169,3 @@ search: url.search, | ||
unmatchedPathnamePart: url.pathname, | ||
url: url, | ||
}; | ||
@@ -169,0 +172,0 @@ var matchEnv = matchMappingAgainstPathname(rootEnv, this.rootMapping, false); |
@@ -40,3 +40,5 @@ import { createRootMapping, matchMappingAgainstPathname } from './Mapping'; | ||
hash: url.hash, | ||
headers: {}, | ||
method: options.method || HTTPMethod.Get, | ||
mountname: '', | ||
params: url.query, | ||
@@ -47,2 +49,3 @@ pathname: '', | ||
router: this, | ||
url: url, | ||
unmatchedPathnamePart: url.pathname, | ||
@@ -49,0 +52,0 @@ }; |
{ | ||
"name": "navi", | ||
"version": "0.10.0", | ||
"version": "0.10.2", | ||
"description": "A router-loader for React.", | ||
@@ -5,0 +5,0 @@ "author": "James K Nelson <james@jamesknelson.com>", |
@@ -133,3 +133,3 @@ # <a href='https://frontarm.com/navi/'><img src='/media/logo-title.png' height='100' alt='Navi Logo' aria-label='frontarm.com/navi' /></a> | ||
To start out, you'll only need two components: `<NavProvider>`, and `<NavRoute>`. You'll want to wrap `<NavProvider>` around your entire App, and then place `<NavRoute>` wherever the content should go. | ||
To start out, you'll only need two components: `<NavProvider>`, and `<NavContent>`. You'll want to wrap `<NavProvider>` around your entire App, and then place `<NavContent>` wherever the content should go. | ||
@@ -139,3 +139,3 @@ ```js | ||
import * as React from 'react' | ||
import { NavLink, NavProvider, NavRoute } from 'react-navi' | ||
import { NavLink, NavProvider, NavContent } from 'react-navi' | ||
import './App.css' | ||
@@ -153,3 +153,3 @@ | ||
</header> | ||
<NavRoute /> | ||
<NavContent /> | ||
</div> | ||
@@ -166,3 +166,3 @@ </NavProvider> | ||
In fact, let's add a couple real-world tweaks as a bonus step, just to see how easy it can be. | ||
To finish off, let's add a couple real-world tweaks as a bonus step, just to see how easy it can be. | ||
@@ -180,6 +180,6 @@ | ||
<NavLoading> | ||
{isLoading => | ||
{loadingRoute => | ||
<div className="App"> | ||
{ | ||
isLoading && | ||
loadingRoute && | ||
<div className="App-loading-bar" /> | ||
@@ -192,3 +192,3 @@ } | ||
</header> | ||
<NavRoute /> | ||
<NavContent /> | ||
</div> | ||
@@ -203,3 +203,3 @@ } | ||
The `<NavLoading>` component accepts a render function as its children, to which it passes the loading state of the content rendered by its nested `<NavRoute>` component. You can use this to show a loading bar or some other indicator. | ||
The `<NavLoading>` component accepts a render function as its children, to which it passes any route whose content is still being fetched, or `undefined` if the curent URL has fully loaded. You can use this to show a loading bar or some other indicator. | ||
@@ -215,6 +215,6 @@ | ||
<NavLoading> | ||
{isLoading => | ||
{loadingRoute => | ||
<div className="App"> | ||
{ | ||
isLoading && | ||
loadingRoute && | ||
<div className="App-loading-bar" /> | ||
@@ -228,3 +228,3 @@ } | ||
<NavNotFoundBoundary render={renderNotFound}> | ||
<NavRoute /> | ||
<NavContent /> | ||
</NavNotFoundBoundary> | ||
@@ -231,0 +231,0 @@ </div> |
import { Router } from './Router' | ||
import { Params } from './URLTools' | ||
import { Params, URLDescriptor } from './URLTools' | ||
import { HTTPMethod } from './HTTPMethod' | ||
// TODO: rename Env -> Request | ||
export interface Env<Context extends object=any> { | ||
readonly context: Context | ||
readonly hash: string | ||
readonly mountname: string | ||
readonly router: Router<Context> | ||
readonly url: URLDescriptor | ||
// TODO: implement | ||
readonly body?: any | ||
readonly headers: { [name: string]: string } | ||
readonly method: HTTPMethod | ||
// TODO: deprecate | ||
readonly params: Params | ||
readonly pathname: string | ||
readonly hash: string | ||
readonly query: Params | ||
readonly search: string | ||
readonly router: Router<Context> | ||
// TODO: remove in favor of just removing mountname from the front of url.pathname | ||
readonly unmatchedPathnamePart: string | ||
} |
@@ -135,8 +135,12 @@ import { MaybeResolvableNode } from './Node' | ||
let mountname = joinPaths(env.mountname, matchedPathname) | ||
return { | ||
context: env.context, | ||
hash: env.hash, | ||
headers: env.headers, | ||
method: env.method, | ||
params: { ...env.params, ...params }, | ||
pathname: joinPaths(env.pathname, matchedPathname), | ||
pathname: mountname, | ||
mountname: mountname, | ||
query: env.query, | ||
@@ -146,2 +150,3 @@ search: env.search, | ||
unmatchedPathnamePart: env.unmatchedPathnamePart.slice(matchedPathname.length) || (appendFinalSlash ? '/' : ''), | ||
url: env.url, | ||
} | ||
@@ -148,0 +153,0 @@ } |
@@ -248,5 +248,7 @@ import { URLDescriptor, createURLDescriptor, joinPaths } from './URLTools' | ||
hash: '', | ||
headers: {}, | ||
method: HTTPMethod.Get, | ||
params: {}, | ||
pathname: '', | ||
mountname: '', | ||
query: url.query, | ||
@@ -256,2 +258,3 @@ search: url.search, | ||
unmatchedPathnamePart: url.pathname, | ||
url: url, | ||
} | ||
@@ -258,0 +261,0 @@ let matchEnv = matchMappingAgainstPathname( |
@@ -73,3 +73,5 @@ import { Switch } from './Switch' | ||
hash: url.hash, | ||
headers: {}, | ||
method: options.method || HTTPMethod.Get, | ||
mountname: '', | ||
params: url.query, | ||
@@ -80,2 +82,3 @@ pathname: '', | ||
router: this, | ||
url: url, | ||
unmatchedPathnamePart: url.pathname, | ||
@@ -82,0 +85,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
640591
12738