Skip to content

Commit e2f4ce1

Browse files
Pavlo AksonovPavlo Aksonov
Pavlo Aksonov
authored and
Pavlo Aksonov
committed
fixes
1 parent f49d5b1 commit e2f4ce1

File tree

6 files changed

+65
-30
lines changed

6 files changed

+65
-30
lines changed

.babelrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 24 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@ function filterParam(data){
2626

2727
let CoreActions = {
2828
push: function(data) {
29-
return Object.assign({type: PUSH}, filterParam(data));
29+
return {
30+
... filterParam(data),
31+
type: PUSH
32+
}
3033
},
3134

3235
pop: function(data = {}) {
33-
return Object.assign({type: POP}, filterParam(data));
36+
return {
37+
... filterParam(data),
38+
type: POP
39+
}
3440
},
3541

3642
dismiss: function(data) {
37-
return Object.assign({type: DISMISS}, filterParam(data));
43+
return {
44+
... filterParam(data),
45+
type: DISMISS
46+
}
3847
},
3948

4049
reset: function(initial) {
@@ -55,23 +64,30 @@ let CoreActions = {
5564
},
5665

5766
custom: function(data) {
58-
return Object.assign({type: CUSTOM}, filterParam(data));
67+
return {
68+
... filterParam(data),
69+
type: CUSTOM
70+
}
5971
},
6072

6173
replace: function(data) {
62-
return Object.assign({type: REPLACE}, filterParam(data));
74+
return {
75+
... filterParam(data),
76+
type: REPLACE
77+
}
6378
},
6479

6580
select: function(data) {
66-
return Object.assign({type: SELECT}, filterParam(data));
81+
return {
82+
... filterParam(data),
83+
type: SELECT
84+
}
6785
}
68-
};
69-
70-
let Actions = Object.assign({}, CoreActions);
86+
}
7187

72-
export {CoreActions};
88+
let Actions = {... CoreActions}
7389

74-
export default Actions;
90+
export {CoreActions, Actions};
7591

7692

7793

index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react-native';
22
const {View, Navigator, Text, StyleSheet} = React;
3-
import Actions from './actions';
3+
import {Actions, CoreActions} from './actions';
44
import {INIT, PUSH, REPLACE, POP, DISMISS, RESET} from './actions';
55

66
import routerReducer from './reducer';
@@ -44,6 +44,10 @@ class Router extends React.Component {
4444
super(props);
4545
this.routes = {};
4646
this.schemas = {};
47+
var {dispatch} = props;
48+
if (!dispatch){
49+
throw new Error("No redux dispatch is provided to Router!");
50+
}
4751

4852
var self = this;
4953
this.initial = props.initial;
@@ -67,7 +71,7 @@ class Router extends React.Component {
6771
}
6872
var args = {name: name, data:data};
6973
var action = child.props.type || 'push';
70-
return RouterActions[action](args);
74+
dispatch(CoreActions[action](args));
7175
};
7276
}
7377
self.routes[name] = child.props;
@@ -82,12 +86,15 @@ class Router extends React.Component {
8286
RouterActions[name] = function(data){
8387
var props = self.extend({}, self.props);
8488
props = self.extend(props, child.props);
85-
return RouterActions.custom({name, props, data})
89+
dispatch(CoreActions.custom({name, props, data}));
8690
};
8791
}
8892
}
8993
});
90-
this.routerActions = bindActionCreators(Actions, props.dispatch);
94+
let dispatched = bindActionCreators(CoreActions, dispatch);
95+
for (var i in dispatched)
96+
RouterActions[i] = dispatched[i];
97+
this.routerActions = RouterActions;
9198
this.initialRoute = this.routes[this.initial] || console.error("No initial route "+this.initial);
9299
this.state = {initial: this.initial};
93100
}
@@ -273,4 +280,4 @@ var styles = StyleSheet.create({
273280
}
274281
});
275282

276-
module.exports = {Router: connect(state=>state.routerReducer)(Router), Action, Actions, Route, Animations, Schema, routerReducer}
283+
module.exports = {Router: connect(state=>state.routerReducer)(Router), Actions, Action, Route, Animations, Schema, routerReducer}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
],
4343
"name": "react-native-redux-router",
4444
"optionalDependencies": {},
45-
"version": "1.0.1"
45+
"version": "1.0.2"
4646
}

reducer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ export default function reducer(state = { routes: [], currentRoute: null}, actio
3939
return {
4040
mode: POP,
4141
routes: [...state.routes.slice(0, state.routes.length - num)],
42-
currentRoute: state.routes[state.routes.length - num - 1]
42+
currentRoute: state.routes[state.routes[state.routes.length - num - 1]]
4343
};
44-
4544
case DISMISS:
4645
if (state.routes.length <= 1) {
4746
throw new Error("Number of routes should be greater than 1");

0 commit comments

Comments
 (0)