Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions lib/attachHistoryModifiers.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Object.defineProperty(exports,"__esModule",{value:true});exports.default=



attachHistoryModifiers;var _urlParse=require('url-parse');var _urlParse2=_interopRequireDefault(_urlParse);var _navigation=require('./navigation');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};} // HACK global.__BUNDLE_START_TIME__ is only present in React Native
var __WEB__=!global.__BUNDLE_START_TIME__&&window.location.pathname;function attachHistoryModifiers(){var _ref=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];var BackAndroid=_ref.BackAndroid;var Linking=_ref.Linking;return function(createStore){return function(reducer,preloadedState,enhancer){
var store=createStore(reducer,preloadedState,enhancer);var
dispatch=store.dispatch;var getState=store.getState;
attachHistoryModifiers;var _urlParse=require('url-parse');var _urlParse2=_interopRequireDefault(_urlParse);var _navigation=require('./navigation');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}var __WEB__=!global.__BUNDLE_START_TIME__&&window.location.pathname;function attachHistoryModifiers(){var _ref=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},BackAndroid=_ref.BackAndroid,Linking=_ref.Linking;
return function(createStore){return function(reducer,preloadedState,enhancer){
var store=createStore(reducer,preloadedState,enhancer);var
dispatch=store.dispatch,getState=store.getState;

if(__WEB__){
window.onpopstate=function(_ref2){var state=_ref2.state;
Expand All @@ -18,22 +18,24 @@ indexOf(state.index);
var lastIndex=getState().navigation.index;

if(newIndex<=lastIndex)dispatch((0,_navigation.back)(true));
if(newIndex>lastIndex)dispatch((0,_navigation.forward)(true));};}


if(newIndex>lastIndex)dispatch((0,_navigation.forward)(true));
};
}
if(BackAndroid){
BackAndroid.addEventListener('hardwareBackPress',function(){var
BackAndroid.addEventListener('hardwareBackPress',function(){var
index=store.getState().navigation.index;
if(index===0)return false;
dispatch((0,_navigation.back)());
return true;});}


return true;
});
}
if(Linking){
Linking.addEventListener('url',function(_ref3){var url=_ref3.url;var _ref4=
new _urlParse2.default(url);var pathname=_ref4.pathname;var query=_ref4.query;var hash=_ref4.hash;
dispatch((0,_navigation.replaceState)(0,0,''+pathname+query+hash));});}



return store;};};}module.exports=exports['default'];
new _urlParse2.default(url),pathname=_ref4.pathname,query=_ref4.query,hash=_ref4.hash;
dispatch((0,_navigation.replaceState)(0,0,''+pathname+query+hash));
});
}

return store;
};};
}module.exports=exports['default'];
54 changes: 28 additions & 26 deletions lib/createOrchestrator.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _jsxFileName='src/createOrchestrator.js';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value" in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _react=require('react');var _react2=_interopRequireDefault(_react);
var _invariant=require('invariant');var _invariant2=_interopRequireDefault(_invariant);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i];}return arr2;}else {return Array.from(arr);}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}
Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _jsxFileName='src\\createOrchestrator.js';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _react=require('react');var _react2=_interopRequireDefault(_react);
var _propTypes=require('prop-types');var _propTypes2=_interopRequireDefault(_propTypes);
var _invariant=require('invariant');var _invariant2=_interopRequireDefault(_invariant);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i];}return arr2;}else{return Array.from(arr);}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}

function makeStackFromPathname(pathname){
var pathArray=pathname.split('/');
pathArray.shift(); // Remove first blank ""
return pathArray;}exports.default=

pathArray.shift();
return pathArray;
}exports.default=

function(fragment){return function(component){
var ComposedComponent=component;

// Handle stateless components

if(!ComposedComponent.render&&!ComposedComponent.prototype.render){
ComposedComponent=function(_Component){_inherits(ComposedComponent,_Component);function ComposedComponent(){_classCallCheck(this,ComposedComponent);return _possibleConstructorReturn(this,Object.getPrototypeOf(ComposedComponent).apply(this,arguments));}_createClass(ComposedComponent,[{key:'render',value:function render()
ComposedComponent=function(_Component){_inherits(ComposedComponent,_Component);function ComposedComponent(){_classCallCheck(this,ComposedComponent);return _possibleConstructorReturn(this,(ComposedComponent.__proto__||Object.getPrototypeOf(ComposedComponent)).apply(this,arguments));}_createClass(ComposedComponent,[{key:'render',value:function render()
{
return component(this.props,this.context);}}]);return ComposedComponent;}(_react.Component);}var


return component(this.props,this.context);
}}]);return ComposedComponent;}(_react.Component);

}var

Orchestrator=function(_Component2){_inherits(Orchestrator,_Component2); // eslint-disable-line react/no-multi-comp
function Orchestrator(props,context){_classCallCheck(this,Orchestrator);var _this2=_possibleConstructorReturn(this,Object.getPrototypeOf(Orchestrator).call(this,
Orchestrator=function(_Component2){_inherits(Orchestrator,_Component2);
function Orchestrator(props,context){_classCallCheck(this,Orchestrator);var _this2=_possibleConstructorReturn(this,(Orchestrator.__proto__||Object.getPrototypeOf(Orchestrator)).call(this,
props,context));_this2.


Expand Down Expand Up @@ -66,12 +67,12 @@ _unsubscribeFromStore=null;_this2.
_updateUrlStack=function(){
var state=_this2.context.store.getState();
var index=state.navigation.index;
// Default to redux store for stack if this is the first
// route and the navStack hasn't been set yet
_this2.setState({
urlStack:makeStackFromPathname(state.navigation.history[index].url)});};(0,_invariant2.default)(context.store,'Couldn\'t find the store on the context. '+'Make sure you have a redux <Provider> at the top '+'of your app.');(0,_invariant2.default)(context.store.getState().navigation,'Couldn\'t find the navigation reducer on the store. '+'Make sure you have react-stack-nav\'s reducer on '+'your root reducer.');return _this2;}_createClass(Orchestrator,[{key:'getChildContext',value:function getChildContext(){return {lastOrchestratorId:this._orchestratorId,orchestratorPath:this._orchestratorPath};}},{key:'componentWillMount',value:function componentWillMount(){var lastOrchestratorId=this.context.lastOrchestratorId;this._orchestratorId=lastOrchestratorId!==undefined?lastOrchestratorId+1:0;this._orchestratorPath=this.context.orchestratorPath?[].concat(_toConsumableArray(this.context.orchestratorPath),[fragment]):[];this._updateUrlStack();this._unsubscribeFromStore=this.context.store.subscribe(this._updateUrlStack);}},{key:'componentWillUnmount',value:function componentWillUnmount(){this._unsubscribeFromStore();}},{key:'render',value:function render()


_this2.setState({
urlStack:makeStackFromPathname(state.navigation.history[index].url)});

};(0,_invariant2.default)(context.store,'Couldn\'t find the store on the context. '+'Make sure you have a redux <Provider> at the top '+'of your app.');(0,_invariant2.default)(context.store.getState().navigation,'Couldn\'t find the navigation reducer on the store. '+'Make sure you have react-stack-nav\'s reducer on '+'your root reducer.');return _this2;}_createClass(Orchestrator,[{key:'getChildContext',value:function getChildContext(){return{lastOrchestratorId:this._orchestratorId,orchestratorPath:this._orchestratorPath};}},{key:'componentWillMount',value:function componentWillMount(){var lastOrchestratorId=this.context.lastOrchestratorId;this._orchestratorId=lastOrchestratorId!==undefined?lastOrchestratorId+1:0;this._orchestratorPath=this.context.orchestratorPath?[].concat(_toConsumableArray(this.context.orchestratorPath),[fragment]):[];this._updateUrlStack();this._unsubscribeFromStore=this.context.store.subscribe(this._updateUrlStack);}},{key:'componentWillUnmount',value:function componentWillUnmount(){this._unsubscribeFromStore();}},{key:'render',value:function render()



Expand All @@ -92,28 +93,29 @@ urlStack:makeStackFromPathname(state.navigation.history[index].url)});};(0,_inva


{
return (
return(
_react2.default.createElement(ComposedComponent,_extends({},
this.props,{
routeFragment:this._routeFragment,__source:{fileName:_jsxFileName,lineNumber:96}})));}},{key:'_routeFragment',get:function get(){var _this3=this;var urlMatchesOrchestratorPath=this._orchestratorPath.reduce(function(prev,curr,i){if(!prev)return false;if(!_this3.state.urlStack[i])return false; // Handle regex orchestrators
if(_this3._orchestratorPath[i] instanceof RegExp){return _this3.state.urlStack[i].match(_this3._orchestratorPath[i]);} // Handle string orchestrators
return _this3.state.urlStack[i]===_this3._orchestratorPath[i];},true);if(!urlMatchesOrchestratorPath)return undefined;return this.state.urlStack[this._orchestratorId]||'';}}]);return Orchestrator;}(_react.Component);
routeFragment:this._routeFragment,__source:{fileName:_jsxFileName,lineNumber:97}})));

}},{key:'_routeFragment',get:function get(){var _this3=this;var urlMatchesOrchestratorPath=this._orchestratorPath.reduce(function(prev,curr,i){if(!prev)return false;if(!_this3.state.urlStack[i])return false;if(_this3._orchestratorPath[i]instanceof RegExp){return _this3.state.urlStack[i].match(_this3._orchestratorPath[i]);}return _this3.state.urlStack[i]===_this3._orchestratorPath[i];},true);if(!urlMatchesOrchestratorPath)return undefined;return this.state.urlStack[this._orchestratorId]||'';}}]);return Orchestrator;}(_react.Component);


Orchestrator.displayName='Orchestrator('+(
_react.Component.displayName||_react.Component.name||'Component')+')';

Orchestrator.contextTypes=_extends({},
Orchestrator.contextTypes,{
store:_react.PropTypes.object,
lastOrchestratorId:_react.PropTypes.number,
orchestratorPath:_react.PropTypes.array});
store:_propTypes2.default.object,
lastOrchestratorId:_propTypes2.default.number,
orchestratorPath:_propTypes2.default.array});


Orchestrator.childContextTypes=_extends({},
Orchestrator.childContextTypes,{
lastOrchestratorId:_react.PropTypes.number,
orchestratorPath:_react.PropTypes.array});
lastOrchestratorId:_propTypes2.default.number,
orchestratorPath:_propTypes2.default.array});


return Orchestrator;};};module.exports=exports['default'];
return Orchestrator;
};};module.exports=exports['default'];
2 changes: 1 addition & 1 deletion lib/index.js
100644 → 100755

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

Loading