redux-first-history
Advanced tools
Comparing version 4.0.0-alpha.3 to 4.0.0-alpha.4
@@ -118,3 +118,2 @@ 'use strict'; | ||
var hLoc = history.location; | ||
if (!locationEqual(sLoc, hLoc)) { | ||
@@ -153,3 +152,2 @@ isReduxTravelling = true; | ||
store.dispatch(locationChangeAction(location, action)); | ||
var state = store.getState(); | ||
@@ -178,3 +176,2 @@ registeredCallback.forEach(function (c) { | ||
}, | ||
//listen tunnel | ||
@@ -215,2 +212,51 @@ listen: function listen(callback) { | ||
return reduxFirstHistory; | ||
}; | ||
/************************************************* reachify ******************************************************/ | ||
var reachify = exports.reachify = function reachify(reduxHistory) { | ||
var transitioning = false; | ||
var resolveTransition = function resolveTransition() {}; | ||
var rrHistory = { | ||
_onTransitionComplete: function _onTransitionComplete() { | ||
transitioning = false; | ||
resolveTransition(); | ||
}, | ||
listen: function listen(listener) { | ||
return reduxHistory.listen(function (location, action) { | ||
return listener({ location: location, action: action }); | ||
}); | ||
}, | ||
navigate: function navigate(to) { | ||
var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
state = _ref4.state, | ||
_ref4$replace = _ref4.replace, | ||
replace = _ref4$replace === undefined ? false : _ref4$replace; | ||
if (transitioning || replace) { | ||
reduxHistory.replace({ pathname: to, state: state, key: '' + Date.now() }); | ||
} else { | ||
reduxHistory.push({ pathname: to, state: state, key: '' + Date.now() }); | ||
} | ||
transitioning = true; | ||
return new Promise(function (res) { | ||
return resolveTransition = res; | ||
}); | ||
} | ||
}; | ||
Object.defineProperty(rrHistory, 'location', { | ||
get: function get() { | ||
return reduxHistory.location; | ||
} | ||
}); | ||
Object.defineProperty(rrHistory, 'transitioning', { | ||
get: function get() { | ||
return transitioning; | ||
} | ||
}); | ||
return rrHistory; | ||
}; |
{ | ||
"name": "redux-first-history", | ||
"version": "4.0.0-alpha.3", | ||
"version": "4.0.0-alpha.4", | ||
"description": "Redux First History - Redux 100% SINGLE-AND-ONLY source of truth! - Tested on react-router v4 and reach-router. ", | ||
@@ -5,0 +5,0 @@ "main": "lib/redux-first-history.js", |
@@ -6,4 +6,6 @@ # redux-first-history | ||
this.context.router.history.location === state.router.location | ||
this.context.route.location === state.router.location | ||
this.props.history.location === state.router.location | ||
this.props.location === state.router.location | ||
withRouter.props.location === state.router.location | ||
``` | ||
@@ -10,0 +12,0 @@ ### Always. Whatever happens. |
@@ -70,3 +70,2 @@ /************************************************* DEFAULT OPTIONS ***************************************************/ | ||
const hLoc = history.location; | ||
if (!locationEqual(sLoc, hLoc)) { | ||
@@ -103,3 +102,2 @@ isReduxTravelling = true; | ||
store.dispatch(locationChangeAction(location, action)); | ||
const state = store.getState(); | ||
@@ -116,3 +114,2 @@ registeredCallback.forEach(c => c(state[routerReducerKey].location, state[routerReducerKey].action)); | ||
goForward: (...args) => store.dispatch(goForward(...args)), | ||
//listen tunnel | ||
@@ -129,3 +126,3 @@ listen: (callback) => { | ||
//location tunnel | ||
//location tunnel | ||
Object.defineProperty(reduxFirstHistory, 'location', { | ||
@@ -153,1 +150,43 @@ get() { | ||
}; | ||
/************************************************* reachify ******************************************************/ | ||
export const reachify = (reduxHistory) => { | ||
let transitioning = false; | ||
let resolveTransition = () => {}; | ||
const rrHistory = { | ||
_onTransitionComplete() { | ||
transitioning = false; | ||
resolveTransition(); | ||
}, | ||
listen(listener) { | ||
return reduxHistory.listen((location, action) => listener({ location, action })); | ||
}, | ||
navigate(to, { state, replace = false } = {}) { | ||
if (transitioning || replace) { | ||
reduxHistory.replace({ pathname: to, state, key: `${Date.now()}` }); | ||
} else { | ||
reduxHistory.push({ pathname: to, state, key: `${Date.now()}` }); | ||
} | ||
transitioning = true; | ||
return new Promise(res => (resolveTransition = res)); | ||
}, | ||
}; | ||
Object.defineProperty(rrHistory, 'location', { | ||
get() { | ||
return reduxHistory.location; | ||
}, | ||
}); | ||
Object.defineProperty(rrHistory, 'transitioning', { | ||
get() { | ||
return transitioning; | ||
}, | ||
}); | ||
return rrHistory; | ||
}; |
153983
13
699
21