Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo Aksonov authored and Pavlo Aksonov committed Nov 24, 2015
1 parent f49d5b1 commit e2f4ce1
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 30 deletions.
6 changes: 0 additions & 6 deletions .babelrc

This file was deleted.

29 changes: 24 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 27 additions & 11 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ function filterParam(data){

let CoreActions = {
push: function(data) {
return Object.assign({type: PUSH}, filterParam(data));
return {
... filterParam(data),
type: PUSH
}
},

pop: function(data = {}) {
return Object.assign({type: POP}, filterParam(data));
return {
... filterParam(data),
type: POP
}
},

dismiss: function(data) {
return Object.assign({type: DISMISS}, filterParam(data));
return {
... filterParam(data),
type: DISMISS
}
},

reset: function(initial) {
Expand All @@ -55,23 +64,30 @@ let CoreActions = {
},

custom: function(data) {
return Object.assign({type: CUSTOM}, filterParam(data));
return {
... filterParam(data),
type: CUSTOM
}
},

replace: function(data) {
return Object.assign({type: REPLACE}, filterParam(data));
return {
... filterParam(data),
type: REPLACE
}
},

select: function(data) {
return Object.assign({type: SELECT}, filterParam(data));
return {
... filterParam(data),
type: SELECT
}
}
};

let Actions = Object.assign({}, CoreActions);
}

export {CoreActions};
let Actions = {... CoreActions}

export default Actions;
export {CoreActions, Actions};



17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react-native';
const {View, Navigator, Text, StyleSheet} = React;
import Actions from './actions';
import {Actions, CoreActions} from './actions';
import {INIT, PUSH, REPLACE, POP, DISMISS, RESET} from './actions';

import routerReducer from './reducer';
Expand Down Expand Up @@ -44,6 +44,10 @@ class Router extends React.Component {
super(props);
this.routes = {};
this.schemas = {};
var {dispatch} = props;
if (!dispatch){
throw new Error("No redux dispatch is provided to Router!");
}

var self = this;
this.initial = props.initial;
Expand All @@ -67,7 +71,7 @@ class Router extends React.Component {
}
var args = {name: name, data:data};
var action = child.props.type || 'push';
return RouterActions[action](args);
dispatch(CoreActions[action](args));
};
}
self.routes[name] = child.props;
Expand All @@ -82,12 +86,15 @@ class Router extends React.Component {
RouterActions[name] = function(data){
var props = self.extend({}, self.props);
props = self.extend(props, child.props);
return RouterActions.custom({name, props, data})
dispatch(CoreActions.custom({name, props, data}));
};
}
}
});
this.routerActions = bindActionCreators(Actions, props.dispatch);
let dispatched = bindActionCreators(CoreActions, dispatch);
for (var i in dispatched)
RouterActions[i] = dispatched[i];
this.routerActions = RouterActions;
this.initialRoute = this.routes[this.initial] || console.error("No initial route "+this.initial);
this.state = {initial: this.initial};
}
Expand Down Expand Up @@ -273,4 +280,4 @@ var styles = StyleSheet.create({
}
});

module.exports = {Router: connect(state=>state.routerReducer)(Router), Action, Actions, Route, Animations, Schema, routerReducer}
module.exports = {Router: connect(state=>state.routerReducer)(Router), Actions, Action, Route, Animations, Schema, routerReducer}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@
],
"name": "react-native-redux-router",
"optionalDependencies": {},
"version": "1.0.1"
"version": "1.0.2"
}
3 changes: 1 addition & 2 deletions reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export default function reducer(state = { routes: [], currentRoute: null}, actio
return {
mode: POP,
routes: [...state.routes.slice(0, state.routes.length - num)],
currentRoute: state.routes[state.routes.length - num - 1]
currentRoute: state.routes[state.routes[state.routes.length - num - 1]]
};

case DISMISS:
if (state.routes.length <= 1) {
throw new Error("Number of routes should be greater than 1");
Expand Down

0 comments on commit e2f4ce1

Please sign in to comment.