@reactive-js/react-router
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
export { RoutableComponentProps, RouterProps, Router } from "./internal/router"; | ||
export { RelativeURI, RoutableComponentProps, RouterProps, Router, } from "./internal/router"; | ||
export { useRoutableState } from "./internal/useRoutableState"; |
@@ -6,5 +6,5 @@ import { StateUpdater, AsyncEnumerableLike } from "@reactive-js/async-enumerable"; | ||
export declare type RelativeURI = { | ||
readonly fragment: string; | ||
readonly path: string; | ||
readonly query: string; | ||
readonly hash: string; | ||
readonly pathname: string; | ||
readonly search: string; | ||
}; | ||
@@ -11,0 +11,0 @@ export declare type RoutableComponentProps = { |
@@ -9,5 +9,5 @@ "use strict"; | ||
const empty = { | ||
path: "", | ||
query: "", | ||
fragment: "", | ||
pathname: "", | ||
search: "", | ||
hash: "", | ||
}; | ||
@@ -32,3 +32,3 @@ const pairify = ([_, oldState], next) => oldState === empty ? [option_1.none, next] : [oldState, next]; | ||
var _a; | ||
return react_2.createElement((_a = routeMap[uri.path]) !== null && _a !== void 0 ? _a : notFound, { | ||
return react_2.createElement((_a = routeMap[uri.pathname]) !== null && _a !== void 0 ? _a : notFound, { | ||
referer, | ||
@@ -35,0 +35,0 @@ uri, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const react_1 = require("react"); | ||
const createURIStateUpdater = (stateUpdater, parse, serialize, stateIsQuery) => (oldURI) => { | ||
const oldSerialized = stateIsQuery ? oldURI.query : oldURI.fragment; | ||
const createURIStateUpdater = (stateUpdater, parse, serialize, stateIssearch) => (oldURI) => { | ||
const oldSerialized = stateIssearch ? oldURI.search : oldURI.hash; | ||
const oldState = parse(oldSerialized); | ||
@@ -11,17 +11,17 @@ const newState = stateUpdater(oldState); | ||
} | ||
else if (stateIsQuery) { | ||
const query = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { query }); | ||
else if (stateIssearch) { | ||
const search = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { search }); | ||
} | ||
else { | ||
const fragment = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { fragment }); | ||
const hash = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { hash }); | ||
} | ||
}; | ||
exports.useRoutableState = (props, parse, serialize, stateIsQuery = false) => { | ||
const { uri: { query, fragment }, uriUpdater, } = props; | ||
const { uri: { search, hash }, uriUpdater, } = props; | ||
const state = react_1.useMemo(() => { | ||
const serialized = stateIsQuery ? query : fragment; | ||
const serialized = stateIsQuery ? search : hash; | ||
return parse(serialized); | ||
}, [parse, query, fragment]); | ||
}, [parse, search, hash]); | ||
const notify = react_1.useCallback((stateUpdater) => { | ||
@@ -28,0 +28,0 @@ uriUpdater(createURIStateUpdater(stateUpdater, parse, serialize, stateIsQuery)); |
@@ -1,2 +0,2 @@ | ||
export { RoutableComponentProps, RouterProps, Router } from "./internal/router"; | ||
export { RelativeURI, RoutableComponentProps, RouterProps, Router, } from "./internal/router"; | ||
export { useRoutableState } from "./internal/useRoutableState"; |
@@ -1,3 +0,3 @@ | ||
export { Router } from "./internal/router"; | ||
export { Router, } from "./internal/router"; | ||
export { useRoutableState } from "./internal/useRoutableState"; | ||
//# sourceMappingURL=index.js.map |
@@ -6,5 +6,5 @@ import { StateUpdater, AsyncEnumerableLike } from "@reactive-js/async-enumerable"; | ||
export declare type RelativeURI = { | ||
readonly fragment: string; | ||
readonly path: string; | ||
readonly query: string; | ||
readonly hash: string; | ||
readonly pathname: string; | ||
readonly search: string; | ||
}; | ||
@@ -11,0 +11,0 @@ export declare type RoutableComponentProps = { |
@@ -7,5 +7,5 @@ import { none, isNone } from "@reactive-js/option"; | ||
const empty = { | ||
path: "", | ||
query: "", | ||
fragment: "", | ||
pathname: "", | ||
search: "", | ||
hash: "", | ||
}; | ||
@@ -30,3 +30,3 @@ const pairify = ([_, oldState], next) => oldState === empty ? [none, next] : [oldState, next]; | ||
var _a; | ||
return createElement((_a = routeMap[uri.path]) !== null && _a !== void 0 ? _a : notFound, { | ||
return createElement((_a = routeMap[uri.pathname]) !== null && _a !== void 0 ? _a : notFound, { | ||
referer, | ||
@@ -33,0 +33,0 @@ uri, |
import { useCallback, useMemo } from "react"; | ||
const createURIStateUpdater = (stateUpdater, parse, serialize, stateIsQuery) => (oldURI) => { | ||
const oldSerialized = stateIsQuery ? oldURI.query : oldURI.fragment; | ||
const createURIStateUpdater = (stateUpdater, parse, serialize, stateIssearch) => (oldURI) => { | ||
const oldSerialized = stateIssearch ? oldURI.search : oldURI.hash; | ||
const oldState = parse(oldSerialized); | ||
@@ -9,17 +9,17 @@ const newState = stateUpdater(oldState); | ||
} | ||
else if (stateIsQuery) { | ||
const query = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { query }); | ||
else if (stateIssearch) { | ||
const search = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { search }); | ||
} | ||
else { | ||
const fragment = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { fragment }); | ||
const hash = serialize(newState); | ||
return Object.assign(Object.assign({}, oldURI), { hash }); | ||
} | ||
}; | ||
export const useRoutableState = (props, parse, serialize, stateIsQuery = false) => { | ||
const { uri: { query, fragment }, uriUpdater, } = props; | ||
const { uri: { search, hash }, uriUpdater, } = props; | ||
const state = useMemo(() => { | ||
const serialized = stateIsQuery ? query : fragment; | ||
const serialized = stateIsQuery ? search : hash; | ||
return parse(serialized); | ||
}, [parse, query, fragment]); | ||
}, [parse, search, hash]); | ||
const notify = useCallback((stateUpdater) => { | ||
@@ -26,0 +26,0 @@ uriUpdater(createURIStateUpdater(stateUpdater, parse, serialize, stateIsQuery)); |
@@ -1,3 +0,3 @@ | ||
export { RoutableComponentProps, RouterProps, Router } from "./internal/router"; | ||
export { RelativeURI, RoutableComponentProps, RouterProps, Router, } from "./internal/router"; | ||
export { useRoutableState } from "./internal/useRoutableState"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,5 +6,5 @@ import { StateUpdater, AsyncEnumerableLike } from "@reactive-js/async-enumerable"; | ||
export declare type RelativeURI = { | ||
readonly fragment: string; | ||
readonly path: string; | ||
readonly query: string; | ||
readonly hash: string; | ||
readonly pathname: string; | ||
readonly search: string; | ||
}; | ||
@@ -11,0 +11,0 @@ export declare type RoutableComponentProps = { |
{ | ||
"name": "@reactive-js/react-router", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"main": "dist/cjs/index.js", | ||
@@ -41,8 +41,8 @@ "module": "dist/esm5/index.js", | ||
"dependencies": { | ||
"@reactive-js/async-enumerable": "^0.0.34", | ||
"@reactive-js/observable": "^0.0.34", | ||
"@reactive-js/option": "^0.0.34", | ||
"@reactive-js/pipe": "^0.0.34", | ||
"@reactive-js/react": "^0.0.34", | ||
"@reactive-js/scheduler": "^0.0.34", | ||
"@reactive-js/async-enumerable": "^0.0.35", | ||
"@reactive-js/observable": "^0.0.35", | ||
"@reactive-js/option": "^0.0.35", | ||
"@reactive-js/pipe": "^0.0.35", | ||
"@reactive-js/react": "^0.0.35", | ||
"@reactive-js/scheduler": "^0.0.35", | ||
"react": "^16.11.0" | ||
@@ -63,3 +63,3 @@ }, | ||
}, | ||
"gitHead": "057b4a00c7069f12169d6f8a406d140769c1a349" | ||
"gitHead": "ee275073cbce47d721480cd774149ad178ae1621" | ||
} |
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
21891
0.16%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated