Skip to content

Commit 626ff3d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents b0a6956 + 4b5d09a commit 626ff3d

26 files changed

+223
-169
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015", "stage-0"]
3+
}

.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@
158158
"before": false,
159159
"after": true
160160
}],
161-
"space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords
161+
"keyword-spacing": 2, // http://eslint.org/docs/rules/space-after-keywords
162162
"space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks
163163
"space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren
164164
"space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops
165-
"space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case
166165
"spaced-comment": 2 // http://eslint.org/docs/rules/spaced-comment
167166
}
168167
}

example/devTools.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createDevTools} from 'redux-devtools';
2+
import { render } from 'react-dom';
3+
import LogMonitor from 'redux-devtools-log-monitor';
4+
import DockMonitor from 'redux-devtools-dock-monitor';
5+
import SliderMonitor from 'redux-slider-monitor';
6+
import React from 'react'
7+
import { Provider } from 'react-redux';
8+
9+
const DevTools = createDevTools(
10+
<DockMonitor toggleVisibilityKey='ctrl-h'
11+
changePositionKey='ctrl-q'
12+
changeMonitorKey='ctrl-m'>
13+
<LogMonitor theme='tomorrow' />
14+
<SliderMonitor keyboardEnabled />
15+
</DockMonitor>
16+
);
17+
18+
export function runDevTools($ngRedux, $rootScope) {
19+
render(
20+
<Provider store={$ngRedux}>
21+
<div>
22+
<DevTools />
23+
</div>
24+
</Provider>,
25+
document.getElementById('devTools')
26+
);
27+
28+
//Hack to reflect state changes when disabling/enabling actions via the monitor
29+
$ngRedux.subscribe(_ => {
30+
setTimeout($rootScope.$apply.bind($rootScope), 100);
31+
});
32+
}
33+
34+
export default DevTools;
35+

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</head>
77
<body>
88
<main ui-view="main"></main>
9+
<div id="devTools"></div>
910
</body>
1011
<script src="/static/bundle.js"></script>
1112
</html>

example/index.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ngRedux from 'ng-redux';
55
import {combineReducers} from 'redux';
66
import thunk from 'redux-thunk';
77
import createLogger from 'redux-logger';
8+
import { default as DevTools, runDevTools} from './devTools';
89

910
import ngReduxRouter from '../src';
1011

@@ -81,6 +82,7 @@ export default angular
8182
<h2>Child View 1</h2>
8283
<button ng-click="stateGo('app.child2')">stateGo View 2</button>
8384
<button ng-click="stateTransitionTo('app.child2')">stateTransitionTo View 2</button>
85+
<button ng-click="stateTransitionTo('app.child3', {id: '4'})">stateTransitionTo View 3, ID: 4</button>
8486
</div>
8587
`
8688
}
@@ -122,6 +124,7 @@ export default angular
122124
template: `
123125
<div class="child-view">
124126
<h2>Child View 3</h2>
127+
<h3>ID: {{router.currentParams.id}}</h3>
125128
<button ng-click="stateGo('app.child3', {id: '1'})">$state.go View 3, ID: 1</button>
126129
<button ng-click="stateGo('app.child3', {id: '2'})">$state.go View 3, ID: 2</button>
127130
<button ng-click="stateGo('app.child3', {id: '3'})">$state.go View 3, ID: 3</button>
@@ -155,27 +158,28 @@ export default angular
155158
router
156159
});
157160

158-
$ngReduxProvider.createStoreWith(reducers, ['ngUiRouterMiddleware', logger, thunk]);
161+
const middlewares = ['ngUiRouterMiddleware', thunk, logger];
162+
const enhancers = [DevTools.instrument()];
163+
164+
$ngReduxProvider.createStoreWith(reducers, middlewares, enhancers);
159165
})
160-
.run(($rootScope, $state, $ngRedux, $urlRouter) => {
166+
.run(runDevTools)
167+
.run(($transitions, $state, $ngRedux) => {
161168

162169
// If save something to the store, dispatch will force state change update
163170
console.log('will do dispatch');
164171
$ngRedux.dispatch({type: 'SOME_ACTION'});
165172
console.log('did dispatch');
166173

167-
$rootScope.$on('$stateChangeStart', function(evt, to, params) {
168-
if (to.prohibited) {
169-
evt.preventDefault();
174+
let matchCriteria = { to: (state) => state.prohibited };
175+
176+
$transitions.onBefore(matchCriteria, ($transition$) => {
177+
if ($transition$.to().prohibited) {
170178
console.log('prohibited state change cancelled');
171-
$state.go('app');
179+
return $state.target('app', {location: 'replace'});
172180
}
173181
});
174182

175-
console.log('$stateChangeStart callback is ready');
176-
console.log('enable $urlRouter listening');
177-
178-
$urlRouter.sync();
179-
$urlRouter.listen();
183+
console.log('$transitions.onBefore callback is ready');
180184
})
181185
.name;

example/package.json

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"devDependencies": {
10-
"babel-core": "5.6.15",
11-
"babel-loader": "5.1.4",
10+
"babel-loader": "6.2.4",
11+
"babel-core": "6.13.1",
1212
"redux-batched-updates": "0.1.0",
13-
"webpack": "1.9.11",
14-
"webpack-dev-server": "1.9.0"
13+
"react": "^15.3.0",
14+
"react-dom": "^15.3.0",
15+
"redux-devtools-dock-monitor": "^1.1.1",
16+
"redux-devtools-log-monitor": "^1.0.11",
17+
"redux-slider-monitor": "^1.0.7",
18+
"webpack": "1.13.1",
19+
"webpack-dev-server": "1.14.1"
1520
},
1621
"license": "MIT",
1722
"dependencies": {
18-
"angular": "^1.4.6",
19-
"angular-ui-router": "^0.2.15",
20-
"ng-redux": "^3.0.0",
21-
"redux": "^3.0.0",
22-
"redux-logger": "1.0.4",
23-
"redux-thunk": "0.1.0"
23+
"angular": "^1.5.1",
24+
"angular-ui-router": "1.0.0-beta.1",
25+
"ng-redux": "^3.3.3",
26+
"react-redux": "^4.4.5",
27+
"redux-devtools": "^3.3.1",
28+
"redux": "^3.5.2",
29+
"redux-logger": "2.6.1",
30+
"redux-thunk": "2.1.0"
2431
},
2532
"engines" : {
26-
"node" : "4.2.1",
27-
"npm" : "2.14.7"
33+
"node" : "6.3.0",
34+
"npm" : "3.10.3"
2835
}
2936
}

example/webpack.config.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ module.exports = {
66
entry: [
77
'webpack-dev-server/client?http://localhost:3000',
88
'webpack/hot/dev-server',
9-
'./index'
9+
'./index',
10+
//Remove the following line to remove devTools
11+
'./devTools.js'
1012
],
1113
output: {
1214
path: path.join(__dirname, 'dist'),
@@ -17,17 +19,14 @@ module.exports = {
1719
new webpack.HotModuleReplacementPlugin(),
1820
new webpack.NoErrorsPlugin()
1921
],
20-
resolve: {
21-
extensions: ['', '.js'],
22-
alias: {
23-
'react': path.join(__dirname, '..', '..', 'node_modules', 'react')
24-
}
25-
},
2622
module: {
2723
loaders: [{
2824
test: /\.js$/,
29-
loaders: ['babel'],
30-
exclude: /node_modules/
25+
loader: 'babel',
26+
exclude: /node_modules/,
27+
query: {
28+
presets: ['es2015', 'stage-0', 'react']
29+
}
3130
}, {
3231
test: /\.css?$/,
3332
loaders: ['style', 'raw'],

package.json

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "redux-ui-router",
3-
"version": "0.5.1",
3+
"version": "0.6.1",
44
"description": "Redux middleware for use with Angular UI Router",
55
"main": "./lib/index.js",
66
"scripts": {
77
"lint": "node node_modules/.bin/eslint src",
88
"clean": "rm -rf lib",
9-
"test": "npm run lint; NODE_ENV=test node node_modules/.bin/mocha --compilers js:babel/register --recursive --require src/__tests__/index.js src/**/*.test.js",
10-
"test:live": "npm run lint; NODE_ENV=test node node_modules/.bin/mocha --compilers js:babel/register --recursive --require src/__tests__/index.js -w src/**/*.test.js",
9+
"test": "npm run lint; NODE_ENV=test node node_modules/.bin/mocha --compilers js:babel-register --recursive --require src/__tests__/index.js src/**/*.test.js",
10+
"test:live": "npm run lint; NODE_ENV=test node node_modules/.bin/mocha --compilers js:babel-register --recursive --require src/__tests__/index.js -w src/**/*.test.js",
1111
"build": "npm run clean; npm run test; node node_modules/.bin/babel src --out-dir lib"
1212
},
1313
"repository": {
@@ -17,30 +17,33 @@
1717
"author": "Neil Fenton (neilff)",
1818
"license": "ISC",
1919
"dependencies": {
20-
"redux": "^3.0.0"
20+
"redux": "^3.5.2"
2121
},
2222
"devDependencies": {
23-
"babel": "5.8.21",
24-
"babel-loader": "5.1.4",
25-
"babel-core": "5.6.15",
26-
"babel-eslint": "5.0.0",
27-
"chai": "3.0.0",
28-
"eslint": "0.24.0",
29-
"mocha": "2.2.5",
30-
"ng-redux": "3.0.0",
31-
"node-libs-browser": "0.5.2",
32-
"sinon": "1.16.1",
33-
"sinon-as-promised": "4.0.0",
3423
"angular": "^1.4.x < 2.0.0",
35-
"angular-ui-router": "^0.2.15"
24+
"angular-ui-router": "1.0.0-beta.1",
25+
"babel-cli": "^6.11.4",
26+
"babel-core": "6.13.1",
27+
"babel-eslint": "6.1.2",
28+
"babel-loader": "6.2.4",
29+
"babel-preset-es2015": "^6.13.1",
30+
"babel-preset-react": "^6.11.1",
31+
"babel-preset-stage-0": "^6.5.0",
32+
"babel-register": "^6.9.0",
33+
"chai": "^3.5.0",
34+
"eslint": "3.1.1",
35+
"mocha": "2.5.3",
36+
"ng-redux": "^3.3.3",
37+
"node-libs-browser": "^1.0.0",
38+
"sinon": "1.17.4",
39+
"sinon-as-promised": "^3.0.1"
3640
},
3741
"peerDependencies": {
3842
"angular": "^1.4.x < 2.0.0",
39-
"angular-ui-router": "^0.2.15"
43+
"angular-ui-router": "^1.0.0-beta.1"
4044
},
41-
"engines" : {
42-
"node" : "4.2.1",
43-
"npm" : "2.14.7"
45+
"engines": {
46+
"node": "6.3.0",
47+
"npm": "3.10.3"
4448
}
45-
4649
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import 'chai';
2+
import sinon from 'sinon';
3+
4+
import RouterListener from '../router-listener';
5+
6+
describe('routerListener', () => {
7+
let routerListener;
8+
let $transitions = {
9+
onStart: sinon.stub(),
10+
onError: sinon.stub(),
11+
onSuccess: sinon.stub()
12+
};
13+
let ngUiStateChangeActions = {
14+
onStateChangeStart: sinon.stub(),
15+
onStateChangeError: sinon.stub(),
16+
onStateChangeSuccess: sinon.stub()
17+
};
18+
19+
beforeEach(() => {
20+
routerListener = RouterListener($transitions, ngUiStateChangeActions);
21+
});
22+
23+
describe('Bootstrap time', () => {
24+
it('must subscribe listeners', () => {
25+
expect($transitions.onStart.calledWith({}, sinon.match.func)).to.equal(true);
26+
expect($transitions.onError.calledWith({}, sinon.match.func)).to.equal(true);
27+
expect($transitions.onSuccess.calledWith({}, sinon.match.func)).to.equal(true);
28+
});
29+
});
30+
31+
describe('listeners', () => {
32+
let $transition$;
33+
before(() => {
34+
let paramsStub = sinon.stub();
35+
paramsStub.withArgs('to').returns('toParams');
36+
paramsStub.withArgs('from').returns('fromParams');
37+
$transition$ = {
38+
to: sinon.stub().returns('to'),
39+
params: paramsStub,
40+
from: sinon.stub().returns('from')
41+
};
42+
});
43+
44+
describe('onStart', () => {
45+
it('must call onStateChangeStart with the transition parameters', () => {
46+
$transitions.onStart.yield($transition$);
47+
expect(ngUiStateChangeActions.onStateChangeStart.calledWith('to', 'toParams', 'from', 'fromParams')).to.equal(true);
48+
});
49+
});
50+
51+
describe('onError', () => {
52+
it('must call onStateChangeError with the transition parameters and the transition Error', () => {
53+
$transition$.error = sinon.stub().returns('transitionError');
54+
$transitions.onError.yield($transition$);
55+
expect(ngUiStateChangeActions.onStateChangeError.calledWith('to', 'toParams', 'from', 'fromParams', 'transitionError')).to.equal(true);
56+
});
57+
});
58+
59+
describe('onSuccess', () => {
60+
it('must call onStateChangeSuccess', () => {
61+
$transitions.onSuccess.yield($transition$);
62+
expect(ngUiStateChangeActions.onStateChangeSuccess.called).to.equal(true);
63+
});
64+
});
65+
});
66+
});

src/__tests__/router-state-reducer.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chai from 'chai';
1+
import 'chai';
22
import routerStateReducer from '../router-state-reducer';
33

44
describe('routerStateReducer', () => {
@@ -17,9 +17,8 @@ describe('routerStateReducer', () => {
1717

1818
it('should set the provided state if the $stateChangeSuccess type is used', () => {
1919
let action = {
20-
type: '@@reduxUiRouter/$stateChangeSuccess',
20+
type: '@@reduxUiRouter/onSuccess',
2121
payload: {
22-
evt: 'evt',
2322
currentState: 'currentState',
2423
currentParams: 'currentParams',
2524
prevState: 'prevState',
@@ -28,7 +27,6 @@ describe('routerStateReducer', () => {
2827
};
2928

3029
let state = routerStateReducer(undefined, action);
31-
chai.should().not.exist(state.evt);
3230
expect(state.currentState).to.equal('currentState');
3331
expect(state.currentParams).to.equal('currentParams');
3432
expect(state.prevState).to.equal('prevState');

0 commit comments

Comments
 (0)