Skip to content

Commit 8847ce8

Browse files
committed
feat(react): add ConnectedUIRouter utility component
1 parent 8170b71 commit 8847ce8

File tree

4 files changed

+913
-26
lines changed

4 files changed

+913
-26
lines changed

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,32 @@
66
"typings": "lib/index.d.ts",
77
"jsnext:main": "lib-esm/index.js",
88
"scripts": {
9-
"prettier":
10-
"prettier --single-quote --trailing-comma es5 --write '{core,react,__{tests,mocks}__}/**/*.{js,ts}'",
9+
"start": "cross-env NODE_ENV=development webpack-dev-server --host 0.0.0.0 --port 8000 --config ./example/webpack.config.js --history-api-fallback --content-base example",
10+
"prettier": "prettier --single-quote --trailing-comma es5 --write '{core,react,__{tests,mocks}__}/**/*.{js,ts}'",
1111
"clean": "shx rm -rf _bundles lib lib-esm build",
12-
"build":
13-
"npm run clean && tsc && tsc -m es6 --outDir lib-esm && NODE_ENV=production webpack"
12+
"build": "npm run clean && tsc && tsc -m es6 --outDir lib-esm && NODE_ENV=production webpack"
1413
},
1514
"author": "Marco Botto",
1615
"license": "MIT",
1716
"devDependencies": {
17+
"@types/react": "^16.0.5",
18+
"@types/react-dom": "^15.5.4",
1819
"@uirouter/core": "^5.0.6",
20+
"@uirouter/react": "^0.5.2",
1921
"awesome-typescript-loader": "^3.2.3",
22+
"cross-env": "^5.0.5",
2023
"jest": "^21.1.0",
2124
"prettier": "^1.7.0",
25+
"prop-types": "^15.5.10",
26+
"react": "^15.6.1",
27+
"react-dom": "^15.6.1",
2228
"redux": "^3.7.2",
2329
"shelljs": "^0.7.8",
2430
"shx": "^0.2.2",
2531
"ts-jest": "^21.0.1",
2632
"typescript": "^2.5.2",
27-
"webpack": "^3.6.0"
33+
"webpack": "^3.6.0",
34+
"webpack-dev-server": "^2.8.2"
2835
},
2936
"dependencies": {}
3037
}

react/ConnectedUIRouter.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { servicesPlugin, UIRouter, UIRouterProps } from '@uirouter/react';
2+
import * as PropTypes from 'prop-types';
3+
import * as React from 'react';
4+
5+
import { createReduxPlugin } from '../core';
6+
7+
export class ConnectedUIRouter extends React.Component<UIRouterProps, any> {
8+
reduxPlugin;
9+
router;
10+
11+
static contextTypes = {
12+
store: PropTypes.object,
13+
};
14+
15+
constructor(props, context) {
16+
super(props, context);
17+
this.reduxPlugin = createReduxPlugin(context.store);
18+
this.router = props.router;
19+
this.router.plugin(servicesPlugin);
20+
props.plugins.forEach(plugin => this.router.plugin(plugin));
21+
this.router.plugin(this.reduxPlugin);
22+
if (props.config) props.config(this.router);
23+
(props.states || []).forEach(state =>
24+
this.router.stateRegistry.register(state)
25+
);
26+
}
27+
28+
render() {
29+
const { children } = this.props;
30+
return <UIRouter router={this.router}>{children}</UIRouter>;
31+
}
32+
}

react/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ConnectedUIRouter';

0 commit comments

Comments
 (0)