Repository URL to install this package:
|
Version:
6.0.0 ▾
|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @todo @@perf @deprecated need to update to not use old context
*/
const react_1 = __importDefault(require("react"));
const prop_types_1 = require("prop-types");
const oneRouter_1 = require("./oneRouter");
exports.oneRouter = oneRouter_1.oneRouter;
/**
* @todo there is no state
* @description provide it all the way down through context
* @withRouter
*/
class OneRouter extends react_1.default.Component {
getChildContext() {
return {
oneRouter: oneRouter_1.oneRouter,
router: Object.assign({}, this.context.router, { history: this.props.history, route: {
location: this.props.history.location,
match: this.state.match,
} }),
};
}
}
OneRouter.childContextTypes = {
router: prop_types_1.object.isRequired,
oneRouter: prop_types_1.object,
};
exports.OneRouter = OneRouter;
// PureComponent
// @withRouter
class OneRouterWrap extends react_1.default.Component {
// can trigger oneRouter here too
// @michael @bhargavi
// // @todo !!!
// oneRouter.onChange(change => {
// // import {sessionContainer} from 'state/container'
// // const { isRegisteredUser, isGuestUser } = sessionContainer
// // () => isRegisteredUser
// // const restrictedRoutes = ['/']
// // oneRouter.set('restrictedRoutes', restrictedRoutes)
// // if (oneRouter.isRestricted === true) {
// // oneRouter.update('/login')
// // }
// })
componentWillMount() {
const props = this.props;
// console.log('PROPS_WILLMOUNT__', JSON.stringify(props, null, 2))
oneRouter_1.oneRouter.props = props;
oneRouter_1.oneRouter.router = this.context.router || props.router;
// oneRouter.history = oneRouter.history.router || oneRouter.history
// const { history, isSSR } = this.props
// if (!isSSR) this.unsubscribeFromHistory = history.listen(this.handleLocationChange)
// this.handleLocationChange(history.location)
}
// componentWillUnmount() {
// if (this.unsubscribeFromHistory) {
// this.unsubscribeFromHistory()
// }
// }
// handleLocationChange = location => {
// this.store.notifyRouteChange(location)
// }
// ===
// componentWillReceiveProps(props) {
// // console.log('___PROPS___', JSON.stringify(props, null, 2))
// props = props || this.props
// oneRouter.props = clone(props)
// oneRouter.router = this.context.router || props.router
// oneRouter.history = oneRouter.history.router || oneRouter.history
// oneRouter.entries()
// }
render() {
return null;
}
}
OneRouterWrap.contextTypes = {
router: prop_types_1.object,
};
exports.OneRouterWrap = OneRouterWrap;
const provideOneRouter = (_props) => {
return react_1.default.createElement(OneRouterWrap, _props);
};
exports.OneRouterContainer = provideOneRouter;
exports.provideOneRouter = provideOneRouter;
// not used?
const withOneRouter = (Target) => {
return class OneRouterWrapper extends react_1.default.Component {
render() {
const attributes = Object.assign({}, oneRouter_1.oneRouter, this.props);
return react_1.default.createElement(Target, Object.assign({}, attributes));
}
};
};
exports.withOneRouter = withOneRouter;
//# sourceMappingURL=OneRouterProvider.js.map