boring-router-react
Advanced tools
Comparing version 0.4.7 to 0.5.0
@@ -6,4 +6,4 @@ "use strict"; | ||
const boring_router_1 = require("boring-router"); | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const debug = debug_1.default('boring-router:react:browser-history'); | ||
const debug_1 = (0, tslib_1.__importDefault)(require("debug")); | ||
const debug = (0, debug_1.default)('boring-router:react:browser-history'); | ||
const NAVIGATE_AWAY_HANDLER_DEFAULT = href => { | ||
@@ -15,40 +15,90 @@ location.href = href; | ||
super(); | ||
this.restoring = false; | ||
this.restoringPromise = Promise.resolve(); | ||
this.lastUsedId = 0; | ||
this.onPopState = (event) => { | ||
let { entries: trackedEntries } = this.tracked; | ||
let state = event.state; | ||
// When using hash mode, entering a new hash directly in the browser will | ||
// also trigger popstate. And in that case state is null. | ||
if (!state) { | ||
void this._push(this.getRefByHRef(location.href), undefined, false); | ||
return; | ||
Object.defineProperty(this, "snapshot", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "tracked", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "restoring", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: false | ||
}); | ||
Object.defineProperty(this, "restoringPromise", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: Promise.resolve() | ||
}); | ||
Object.defineProperty(this, "restoringPromiseResolver", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "lastUsedId", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: 0 | ||
}); | ||
Object.defineProperty(this, "prefix", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "hash", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "onPopState", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: (event) => { | ||
let { entries: trackedEntries } = this.tracked; | ||
let state = event.state; | ||
// When using hash mode, entering a new hash directly in the browser will | ||
// also trigger popstate. And in that case state is null. | ||
if (!state) { | ||
void this._push(this.getRefByHRef(location.href), undefined, false); | ||
return; | ||
} | ||
let { id, data } = state; | ||
if (id > this.lastUsedId) { | ||
this.lastUsedId = id; | ||
} | ||
let entries = [...trackedEntries]; | ||
let index = entries.findIndex(entry => entry.id >= id); | ||
if (index < 0 || entries[index].id > id) { | ||
entries.splice(index < 0 ? entries.length : index, 0, { | ||
id, | ||
ref: this.getRefByHRef(this.url), | ||
data, | ||
}); | ||
} | ||
let snapshot = { | ||
entries, | ||
active: id, | ||
}; | ||
this.tracked = snapshot; | ||
if (this.restoring) { | ||
this.stepRestoration(); | ||
return; | ||
} | ||
this.snapshot = snapshot; | ||
debug('pop', snapshot); | ||
this.emitChange(snapshot); | ||
} | ||
let { id, data } = state; | ||
if (id > this.lastUsedId) { | ||
this.lastUsedId = id; | ||
} | ||
let entries = [...trackedEntries]; | ||
let index = entries.findIndex(entry => entry.id >= id); | ||
if (index < 0 || entries[index].id > id) { | ||
entries.splice(index < 0 ? entries.length : index, 0, { | ||
id, | ||
ref: this.getRefByHRef(this.url), | ||
data, | ||
}); | ||
} | ||
let snapshot = { | ||
entries, | ||
active: id, | ||
}; | ||
this.tracked = snapshot; | ||
if (this.restoring) { | ||
this.stepRestoration(); | ||
return; | ||
} | ||
this.snapshot = snapshot; | ||
debug('pop', snapshot); | ||
this.emitChange(snapshot); | ||
}; | ||
}); | ||
this.prefix = prefix; | ||
@@ -176,3 +226,3 @@ this.hash = hash; | ||
let lastTrackedIndex = trackedEntries.length - 1; | ||
let trackedActiveIndex = boring_router_1.getActiveHistoryEntryIndex(tracked); | ||
let trackedActiveIndex = (0, boring_router_1.getActiveHistoryEntryIndex)(tracked); | ||
let minLength = Math.min(expectedEntries.length, trackedEntries.length); | ||
@@ -183,3 +233,3 @@ let firstMismatchedIndex = 0; | ||
let trackedEntry = trackedEntries[firstMismatchedIndex]; | ||
if (!boring_router_1.isHistoryEntryEqual(expectedEntry, trackedEntry)) { | ||
if (!(0, boring_router_1.isHistoryEntryEqual)(expectedEntry, trackedEntry)) { | ||
break; | ||
@@ -234,4 +284,4 @@ } | ||
restoreActive() { | ||
let expectedActiveIndex = boring_router_1.getActiveHistoryEntryIndex(this.snapshot); | ||
let trackedActiveIndex = boring_router_1.getActiveHistoryEntryIndex(this.tracked); | ||
let expectedActiveIndex = (0, boring_router_1.getActiveHistoryEntryIndex)(this.snapshot); | ||
let trackedActiveIndex = (0, boring_router_1.getActiveHistoryEntryIndex)(this.tracked); | ||
if (trackedActiveIndex < expectedActiveIndex) { | ||
@@ -274,3 +324,3 @@ history.forward(); | ||
let { entries } = tracked; | ||
let activeIndex = boring_router_1.getActiveHistoryEntryIndex(tracked); | ||
let activeIndex = (0, boring_router_1.getActiveHistoryEntryIndex)(tracked); | ||
let snapshot = { | ||
@@ -277,0 +327,0 @@ entries: [...entries.slice(0, activeIndex + 1), { id, ref, data }], |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./link"), exports); | ||
tslib_1.__exportStar(require("./nav-link"), exports); | ||
tslib_1.__exportStar(require("./route"), exports); | ||
tslib_1.__exportStar(require("./browser-history"), exports); | ||
(0, tslib_1.__exportStar)(require("./link"), exports); | ||
(0, tslib_1.__exportStar)(require("./nav-link"), exports); | ||
(0, tslib_1.__exportStar)(require("./route"), exports); | ||
(0, tslib_1.__exportStar)(require("./browser-history"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -12,4 +12,2 @@ import { RouteBuilder, RouteMatch, RouteMatchSharedToParamDict } from 'boring-router'; | ||
} | ||
export declare const Link: (<T extends RouteMatch<import("boring-router").GeneralParamDict, import("boring-router").NextRouteMatch<import("boring-router").GeneralParamDict, string | undefined, string>, string | undefined, string, object> | RouteBuilder<string>>(props: LinkProps<T>) => JSX.Element) & { | ||
displayName: string; | ||
}; | ||
export declare const Link: <T extends RouteMatch<import("boring-router").GeneralParamDict, import("boring-router").NextRouteMatch<import("boring-router").GeneralParamDict, string | undefined, string>, string | undefined, string, object> | RouteBuilder<string>>(props: LinkProps<T>) => JSX.Element; |
@@ -6,10 +6,10 @@ "use strict"; | ||
const boring_router_1 = require("boring-router"); | ||
const mobx_react_lite_1 = require("mobx-react-lite"); | ||
const react_1 = tslib_1.__importDefault(require("react")); | ||
const mobx_react_1 = require("mobx-react"); | ||
const react_1 = (0, tslib_1.__importDefault)(require("react")); | ||
const _utils_1 = require("./@utils"); | ||
exports.Link = mobx_react_lite_1.observer((props) => { | ||
exports.Link = (0, mobx_react_1.observer)((props) => { | ||
let { to, params, replace = false, toggle = false, | ||
// Do not provide `leave` option default value, check out its references. | ||
leave, onClick, ...restProps } = props; | ||
let store = mobx_react_lite_1.useLocalStore(props => { | ||
let store = (0, mobx_react_1.useLocalStore)(props => { | ||
return { | ||
@@ -34,3 +34,3 @@ get href() { | ||
let { to, params, leave, toggle, replace, onClick } = props; | ||
return _utils_1.composeEventHandler([ | ||
return (0, _utils_1.composeEventHandler)([ | ||
onClick, | ||
@@ -66,4 +66,4 @@ (event) => { | ||
}, { to, params, leave, toggle, replace, onClick }); | ||
return (react_1.default.createElement("a", Object.assign({}, restProps, { href: store.href, onClick: store.composedOnClick }))); | ||
return (react_1.default.createElement("a", { ...restProps, href: store.href, onClick: store.composedOnClick })); | ||
}); | ||
//# sourceMappingURL=link.js.map |
@@ -8,4 +8,2 @@ /// <reference types="react" /> | ||
} | ||
export declare const NavLink: (<T extends RouteMatch<import("boring-router").GeneralParamDict, import("boring-router").NextRouteMatch<import("boring-router").GeneralParamDict, string | undefined, string>, string | undefined, string, object> | RouteBuilder<string>>(props: NavLinkProps<T>) => JSX.Element) & { | ||
displayName: string; | ||
}; | ||
export declare const NavLink: <T extends RouteMatch<import("boring-router").GeneralParamDict, import("boring-router").NextRouteMatch<import("boring-router").GeneralParamDict, string | undefined, string>, string | undefined, string, object> | RouteBuilder<string>>(props: NavLinkProps<T>) => JSX.Element; |
@@ -6,9 +6,9 @@ "use strict"; | ||
const boring_router_1 = require("boring-router"); | ||
const classnames_1 = tslib_1.__importDefault(require("classnames")); | ||
const mobx_react_lite_1 = require("mobx-react-lite"); | ||
const react_1 = tslib_1.__importDefault(require("react")); | ||
const classnames_1 = (0, tslib_1.__importDefault)(require("classnames")); | ||
const mobx_react_1 = require("mobx-react"); | ||
const react_1 = (0, tslib_1.__importDefault)(require("react")); | ||
const link_1 = require("./link"); | ||
exports.NavLink = mobx_react_lite_1.observer((props) => { | ||
exports.NavLink = (0, mobx_react_1.observer)((props) => { | ||
let { to, exact = false } = props; | ||
let store = mobx_react_lite_1.useLocalStore(props => { | ||
let store = (0, mobx_react_1.useLocalStore)(props => { | ||
return { | ||
@@ -25,2 +25,3 @@ get route() { | ||
else { | ||
// eslint-disable-next-line @mufan/no-unnecessary-type-assertion | ||
return to; | ||
@@ -37,4 +38,4 @@ } | ||
let { className, activeClassName = 'active', exact: _exact, ...restProps } = props; | ||
return (react_1.default.createElement(link_1.Link, Object.assign({ className: classnames_1.default(className, store.matched && activeClassName) }, restProps))); | ||
return (react_1.default.createElement(link_1.Link, { className: (0, classnames_1.default)(className, store.matched && activeClassName), ...restProps })); | ||
}); | ||
//# sourceMappingURL=nav-link.js.map |
@@ -14,4 +14,2 @@ import { RouteMatch } from 'boring-router'; | ||
} | ||
export declare const Route: (<TRouteMatch extends RouteMatch<import("boring-router").GeneralParamDict, import("boring-router").NextRouteMatch<import("boring-router").GeneralParamDict, string | undefined, string>, string | undefined, string, object>>({ match, exact, component: RouteComponent, children, }: RouteProps<TRouteMatch>) => any) & { | ||
displayName: string; | ||
}; | ||
export declare const Route: <TRouteMatch extends RouteMatch<import("boring-router").GeneralParamDict, import("boring-router").NextRouteMatch<import("boring-router").GeneralParamDict, string | undefined, string>, string | undefined, string, object>>({ match, exact, component: RouteComponent, children, }: RouteProps<TRouteMatch>) => any; |
@@ -5,5 +5,5 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const mobx_react_lite_1 = require("mobx-react-lite"); | ||
const react_1 = tslib_1.__importDefault(require("react")); | ||
exports.Route = mobx_react_lite_1.observer(({ match, exact, component: RouteComponent, children, }) => { | ||
const mobx_react_1 = require("mobx-react"); | ||
const react_1 = (0, tslib_1.__importDefault)(require("react")); | ||
exports.Route = (0, mobx_react_1.observer)(({ match, exact, component: RouteComponent, children, }) => { | ||
let matches = Array.isArray(match) ? match : [match]; | ||
@@ -10,0 +10,0 @@ let firstMatch = matches.find(match => exact ? match.$exact : match.$matched); |
{ | ||
"name": "boring-router-react", | ||
"version": "0.4.7", | ||
"version": "0.5.0", | ||
"description": "A type-safe MobX router with parallel routing support.", | ||
"license": "MIT", | ||
"author": "Chengdu Mufan Technology Co., Ltd.", | ||
"repository": { | ||
@@ -9,3 +11,2 @@ "type": "git", | ||
}, | ||
"license": "MIT", | ||
"main": "bld/library/index.js", | ||
@@ -20,20 +21,20 @@ "types": "bld/library/index.d.ts", | ||
"peerDependencies": { | ||
"boring-router": "0.3", | ||
"mobx": "5", | ||
"react": "16" | ||
"boring-router": "0.5", | ||
"mobx": "6", | ||
"react": "17" | ||
}, | ||
"devDependencies": { | ||
"@types/classnames": "^2.2.10", | ||
"@types/debug": "^4.1.5", | ||
"mobx": "^5.15.4", | ||
"react": "^16.13.1" | ||
"@types/classnames": "^2.3.1", | ||
"@types/debug": "^4.1.7", | ||
"mobx": "^6.3.3", | ||
"react": "^17.0.2" | ||
}, | ||
"dependencies": { | ||
"classnames": "^2.2.6", | ||
"debug": "^4.1.1", | ||
"mobx-react-lite": "^2.0.7", | ||
"tslang": "^0.1.22", | ||
"tslib": "^2.0.0" | ||
"classnames": "^2.3.1", | ||
"debug": "^4.3.2", | ||
"mobx-react": "^7.2.0", | ||
"tslang": "^0.1.23", | ||
"tslib": "^2.3.1" | ||
}, | ||
"gitHead": "88c7eade23aac2c02b83e46207f72f337e3d8cab" | ||
"gitHead": "31837e1d406f81c6927d97987e48be30bcc1ab1e" | ||
} |
@@ -6,1 +6,5 @@ # Boring Router React | ||
Checkout https://makeflow.github.io/boring-router/ for documentation. | ||
## License | ||
MIT License. |
@@ -14,5 +14,6 @@ import { | ||
const NAVIGATE_AWAY_HANDLER_DEFAULT: BrowserHistoryNavigateAwayHandler = href => { | ||
location.href = href; | ||
}; | ||
const NAVIGATE_AWAY_HANDLER_DEFAULT: BrowserHistoryNavigateAwayHandler = | ||
href => { | ||
location.href = href; | ||
}; | ||
@@ -19,0 +20,0 @@ type BrowserHistoryEntry<TData> = HistoryEntry<number, TData>; |
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
81375
28
1203
1
10
+ Addedmobx-react@^7.2.0
+ Addedboring-router@0.5.20(transitive)
+ Addedmobx@6.13.6(transitive)
+ Addedmobx-react@7.6.0(transitive)
+ Addedmobx-react-lite@3.4.3(transitive)
+ Addedreact@17.0.2(transitive)
- Removedmobx-react-lite@^2.0.7
- Removedboring-router@0.3.13(transitive)
- Removedmobx@5.15.7(transitive)
- Removedmobx-react-lite@2.2.2(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact@16.14.0(transitive)
- Removedreact-is@16.13.1(transitive)
Updatedclassnames@^2.3.1
Updateddebug@^4.3.2
Updatedtslang@^0.1.23
Updatedtslib@^2.3.1