Skip to content

Commit a56da69

Browse files
authored
Release/0.7.1 (#93)
* Support for angular-ui-router 1.0.0-beta.1 (#64) * Support to ui-router 1.0.0-beta.1 - onStateNotFound action was removed - evt parameter was removed from onStateChangeStart and onStateChangeError - example using redux-devtools * The router listener was simplified * fixed incorrect params being passed in router middleware on STATE_CHANGE_SUCCESS * fix #66 missing parameters passed on transition onStart. Add tests for router-listener (#67) * Fixed the prev state and params in the redux router state getting set… (#68) * Fixed the prev state and params in the redux router state getting set to the current state and params by changing the way that the STATE_CHANGE_SUCCESS handler in the middleware accesses the previous state and params. * added options to the state change start action payload for middle wares etc. * Add `href` property to the router state object (#51) * Add `href` property to the router state object Adding `href` to the router state object gives access to the `$state.href` function in React code. This allows the creation of urls for states, which is critical when a component links to another part of the app and should be crawlable by a crawler. * Update licenser test Include `href` payload key in tests * Fix tests and lint (#70) * Fix tests for `onStart` and `onError` Adds a stub for the new options param added in commit 994b8d0 * Fix lint error * Restrict to node v6 and higher (#75) * Added MIT license (#79) * Added stateChangeFinish action to ensure state changes are set in the… (#80) * Added stateChangeFinish action to ensure state changes are set in the app state before components are instantiated * added and fixed tests * updated ui-router to 1.0-beta.3 * missing test * fixed test * upgraded ui-router to 1.0.0-rc1 and fixed node engine bug * upgraded ui-router to 1.0.0-rc1 and fixed node engine bug * 0.7.0-rc.1 * Expose state activation actions as injectable factory (#81) * Expose state activation actions as a factory * Integrate default state activation actions wrap state activation actions into factory * Create state-activation-actions.test.js * Update function name * added the state activation actions as injectable factory * 0.7.1-rc.1 * Fixed up example * bumped patch release * Upgraded to new ui-router package name
1 parent 06b9431 commit a56da69

30 files changed

+1680
-991
lines changed

.babelrc

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

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: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
import angular from 'angular';
2-
import uiRouter from 'angular-ui-router';
2+
import uiRouter from '@uirouter/angularjs';
33

44
import ngRedux from 'ng-redux';
5-
import {combineReducers} from 'redux';
5+
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

11-
import {
12-
router,
13-
stateGo,
14-
stateReload,
15-
stateTransitionTo
16-
}
17-
from '../src';
12+
import { router, stateGo, stateReload, stateTransitionTo } from '../src';
1813

1914
const routerActions = {
2015
stateGo,
2116
stateReload,
22-
stateTransitionTo
17+
stateTransitionTo,
2318
};
2419

2520
export default angular
26-
.module('demoApp', [
27-
uiRouter,
28-
ngRedux,
29-
ngReduxRouter
30-
])
21+
.module('demoApp', [uiRouter, ngRedux, ngReduxRouter])
3122
.config(($urlRouterProvider, $stateProvider) => {
3223
$urlRouterProvider.otherwise('/app');
3324

@@ -60,21 +51,24 @@ export default angular
6051

6152
$ngRedux.connect(state => {
6253
return {
63-
globalState: state
54+
globalState: state,
6455
};
65-
})($scope)
66-
}
67-
}
68-
}
56+
})($scope);
57+
},
58+
},
59+
},
6960
})
7061
.state('app.child1', {
7162
url: '/child1?hello?optional',
7263
views: {
7364
child: {
7465
controller: ($scope, $ngRedux) => {
75-
let disconnect = $ngRedux.connect((state) => state, routerActions)($scope);
66+
const disconnect = $ngRedux.connect(
67+
state => state,
68+
routerActions
69+
)($scope);
7670

77-
$scope.$on('$destroy', disconnect)
71+
$scope.$on('$destroy', disconnect);
7872
},
7973
template: `
8074
<div class="child-view">
@@ -83,18 +77,21 @@ export default angular
8377
<button ng-click="stateTransitionTo('app.child2')">stateTransitionTo View 2</button>
8478
<button ng-click="stateTransitionTo('app.child3', {id: '4'})">stateTransitionTo View 3, ID: 4</button>
8579
</div>
86-
`
87-
}
88-
}
80+
`,
81+
},
82+
},
8983
})
9084
.state('app.child2', {
9185
url: '/child2',
9286
views: {
9387
child: {
9488
controller: ($scope, $ngRedux) => {
95-
let disconnect = $ngRedux.connect((state) => state, routerActions)($scope);
89+
const disconnect = $ngRedux.connect(
90+
state => state,
91+
routerActions
92+
)($scope);
9693

97-
$scope.$on('$destroy', disconnect)
94+
$scope.$on('$destroy', disconnect);
9895
},
9996
template: `
10097
<div class="child-view">
@@ -103,22 +100,25 @@ export default angular
103100
<button ng-click="stateReload('app.child1')">$state.reload</button>
104101
<button ng-click="stateGo('app.child1',{hello: 'world', optional: true})">$state.go to View 1 with Params</button>
105102
</div>
106-
`
107-
}
108-
}
103+
`,
104+
},
105+
},
109106
})
110107
.state('app.child3', {
111108
url: '/child3?id',
112109
params: {
113-
hello: 'world'
110+
hello: 'world',
114111
},
115112
reloadOnSearch: false,
116113
views: {
117114
child: {
118115
controller: ($scope, $ngRedux) => {
119-
let disconnect = $ngRedux.connect((state) => state, routerActions)($scope);
116+
const disconnect = $ngRedux.connect(
117+
state => state,
118+
routerActions
119+
)($scope);
120120

121-
$scope.$on('$destroy', disconnect)
121+
$scope.$on('$destroy', disconnect);
122122
},
123123
template: `
124124
<div class="child-view">
@@ -128,9 +128,9 @@ export default angular
128128
<button ng-click="stateGo('app.child3', {id: '2'})">$state.go View 3, ID: 2</button>
129129
<button ng-click="stateGo('app.child3', {id: '3'})">$state.go View 3, ID: 3</button>
130130
</div>
131-
`
132-
}
133-
}
131+
`,
132+
},
133+
},
134134
})
135135
.state('app.child4', {
136136
url: '/child4',
@@ -142,42 +142,41 @@ export default angular
142142
<h2>Child View 4</h2>
143143
<div>This state is prohibited. You should've been redirected to the root.</div>
144144
</div>
145-
`
146-
}
147-
}
148-
})
145+
`,
146+
},
147+
},
148+
});
149149
})
150-
.config(($ngReduxProvider) => {
150+
.config($ngReduxProvider => {
151151
const logger = createLogger({
152152
level: 'info',
153-
collapsed: true
153+
collapsed: true,
154154
});
155155

156156
const reducers = combineReducers({
157-
router
157+
router,
158158
});
159159

160-
$ngReduxProvider.createStoreWith(reducers, ['ngUiRouterMiddleware', logger, thunk]);
161-
})
162-
.run(($rootScope, $state, $ngRedux, $urlRouter) => {
160+
const middlewares = ['ngUiRouterMiddleware', thunk, logger];
161+
const enhancers = [DevTools.instrument()];
163162

163+
$ngReduxProvider.createStoreWith(reducers, middlewares, enhancers);
164+
})
165+
.run(runDevTools)
166+
.run(($transitions, $state, $ngRedux) => {
164167
// If save something to the store, dispatch will force state change update
165168
console.log('will do dispatch');
166-
$ngRedux.dispatch({type: 'SOME_ACTION'});
169+
$ngRedux.dispatch({ type: 'SOME_ACTION' });
167170
console.log('did dispatch');
168171

169-
$rootScope.$on('$stateChangeStart', function(evt, to, params) {
170-
if (to.prohibited) {
171-
evt.preventDefault();
172+
const matchCriteria = { to: state => state.prohibited };
173+
174+
$transitions.onBefore(matchCriteria, $transition$ => {
175+
if ($transition$.to().prohibited) {
172176
console.log('prohibited state change cancelled');
173-
$state.go('app');
177+
return $state.target('app', { location: 'replace' });
174178
}
175179
});
176180

177-
console.log('$stateChangeStart callback is ready');
178-
console.log('enable $urlRouter listening');
179-
180-
$urlRouter.sync();
181-
$urlRouter.listen();
182-
})
183-
.name;
181+
console.log('$transitions.onBefore callback is ready');
182+
}).name;

example/package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,29 @@
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"devDependencies": {
10+
"babel-core": "6.13.1",
1011
"babel-loader": "6.2.4",
11-
"babel-core": "6.5.2",
12+
"react": "^15.3.0",
13+
"react-dom": "^15.3.0",
1214
"redux-batched-updates": "0.1.0",
15+
"redux-devtools-dock-monitor": "^1.1.1",
16+
"redux-devtools-log-monitor": "^1.0.11",
17+
"redux-slider-monitor": "^1.0.7",
1318
"webpack": "1.13.1",
1419
"webpack-dev-server": "1.14.1"
1520
},
1621
"license": "MIT",
1722
"dependencies": {
23+
"@uirouter/angularjs": "^1.0.3",
1824
"angular": "^1.5.1",
19-
"angular-ui-router": "0.4.2",
2025
"ng-redux": "^3.3.3",
26+
"react-redux": "^4.4.5",
2127
"redux": "^3.5.2",
28+
"redux-devtools": "^3.3.1",
2229
"redux-logger": "2.6.1",
2330
"redux-thunk": "2.1.0"
2431
},
25-
"engines" : {
26-
"node" : ">=6.0.0"
32+
"engines": {
33+
"node": ">=6.0.0"
2734
}
2835
}

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'],

0 commit comments

Comments
 (0)