redux-devtools
Advanced tools
Comparing version 3.0.0-alpha-7 to 3.0.0-beta-2
@@ -21,2 +21,4 @@ 'use strict'; | ||
var _reactRedux = require('react-redux'); | ||
var _instrument = require('./instrument'); | ||
@@ -26,23 +28,16 @@ | ||
var _connectMonitor = require('./connectMonitor'); | ||
function createDevTools(children) { | ||
var monitorElement = _react.Children.only(children); | ||
var monitorProps = monitorElement.props; | ||
var Monitor = monitorElement.type; | ||
var ConnectedMonitor = _reactRedux.connect(function (state) { | ||
return state; | ||
})(Monitor); | ||
var enhancer = _instrument2['default'](function (state, action) { | ||
return Monitor.reducer(state, action, monitorProps); | ||
}); | ||
var _connectMonitor2 = _interopRequireDefault(_connectMonitor); | ||
function createDevTools(monitor) { | ||
var Monitor = _connectMonitor2['default'](monitor); | ||
return (function (_Component) { | ||
_inherits(DevTools, _Component); | ||
function DevTools() { | ||
_classCallCheck(this, DevTools); | ||
_Component.apply(this, arguments); | ||
} | ||
DevTools.prototype.render = function render() { | ||
return _react2['default'].createElement(Monitor, _extends({}, this.props, { | ||
store: this.context.store.instrumentedStore })); | ||
}; | ||
_createClass(DevTools, null, [{ | ||
@@ -57,3 +52,3 @@ key: 'contextTypes', | ||
value: function value() { | ||
return _instrument2['default'](Monitor.reducer); | ||
return enhancer; | ||
}, | ||
@@ -63,2 +58,14 @@ enumerable: true | ||
function DevTools(props, context) { | ||
_classCallCheck(this, DevTools); | ||
_Component.call(this, props, context); | ||
this.liftedStore = context.store.liftedStore; | ||
} | ||
DevTools.prototype.render = function render() { | ||
return _react2['default'].createElement(ConnectedMonitor, _extends({}, monitorProps, { | ||
store: this.liftedStore })); | ||
}; | ||
return DevTools; | ||
@@ -65,0 +72,0 @@ })(_react.Component); |
@@ -10,2 +10,3 @@ 'use strict'; | ||
exports.instrument = _interopRequire(_instrument); | ||
exports.ActionCreators = _instrument.ActionCreators; | ||
exports.ActionTypes = _instrument.ActionTypes; | ||
@@ -12,0 +13,0 @@ |
@@ -8,2 +8,9 @@ 'use strict'; | ||
exports['default'] = instrument; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _lodashArrayDifference = require('lodash/array/difference'); | ||
var _lodashArrayDifference2 = _interopRequireDefault(_lodashArrayDifference); | ||
var ActionTypes = { | ||
@@ -16,3 +23,4 @@ PERFORM_ACTION: 'PERFORM_ACTION', | ||
TOGGLE_ACTION: 'TOGGLE_ACTION', | ||
JUMP_TO_STATE: 'JUMP_TO_STATE' | ||
JUMP_TO_STATE: 'JUMP_TO_STATE', | ||
IMPORT_STATE: 'IMPORT_STATE' | ||
}; | ||
@@ -45,4 +53,4 @@ | ||
toggleAction: function toggleAction(index) { | ||
return { type: ActionTypes.TOGGLE_ACTION, index: index }; | ||
toggleAction: function toggleAction(id) { | ||
return { type: ActionTypes.TOGGLE_ACTION, id: id }; | ||
}, | ||
@@ -52,2 +60,6 @@ | ||
return { type: ActionTypes.JUMP_TO_STATE, index: index }; | ||
}, | ||
importState: function importState(nextLiftedState) { | ||
return { type: ActionTypes.IMPORT_STATE, nextLiftedState: nextLiftedState }; | ||
} | ||
@@ -59,12 +71,2 @@ }; | ||
function toggle(obj, key) { | ||
var clone = _extends({}, obj); | ||
if (clone[key]) { | ||
delete clone[key]; | ||
} else { | ||
clone[key] = true; | ||
} | ||
return clone; | ||
} | ||
/** | ||
@@ -99,8 +101,8 @@ * Computes the next entry in the log by applying an action. | ||
*/ | ||
function recomputeStates(reducer, committedState, stagedActions, skippedActions) { | ||
function recomputeStates(reducer, committedState, actionsById, stagedActionIds, skippedActionIds) { | ||
var computedStates = []; | ||
for (var i = 0; i < stagedActionIds.length; i++) { | ||
var actionId = stagedActionIds[i]; | ||
var action = actionsById[actionId].action; | ||
for (var i = 0; i < stagedActions.length; i++) { | ||
var action = stagedActions[i]; | ||
var previousEntry = computedStates[i - 1]; | ||
@@ -110,3 +112,3 @@ var previousState = previousEntry ? previousEntry.state : committedState; | ||
var shouldSkip = Boolean(skippedActions[i]); | ||
var shouldSkip = skippedActionIds.indexOf(actionId) > -1; | ||
var entry = shouldSkip ? previousEntry : computeNextEntry(reducer, action, previousState, previousError); | ||
@@ -121,11 +123,23 @@ | ||
/** | ||
* Lifts an app's action into an action on the lifted store. | ||
*/ | ||
function liftAction(action) { | ||
return ActionCreators.performAction(action); | ||
} | ||
/** | ||
* Creates a history state reducer from an app's reducer. | ||
*/ | ||
function createHistoryReducer(reducer, initialCommittedState) { | ||
var initialHistoryState = { | ||
function liftReducerWith(reducer, initialCommittedState, monitorReducer) { | ||
var initialLiftedState = { | ||
monitorState: monitorReducer(undefined, {}), | ||
nextActionId: 1, | ||
actionsById: { | ||
0: liftAction(INIT_ACTION) | ||
}, | ||
stagedActionIds: [0], | ||
skippedActionIds: [], | ||
committedState: initialCommittedState, | ||
stagedActions: [INIT_ACTION], | ||
skippedActions: {}, | ||
currentStateIndex: 0, | ||
timestamps: [Date.now()] | ||
computedStates: undefined | ||
}; | ||
@@ -136,39 +150,55 @@ | ||
*/ | ||
return function (historyState, historyAction) { | ||
if (historyState === undefined) historyState = initialHistoryState; | ||
return function (liftedState, liftedAction) { | ||
if (liftedState === undefined) liftedState = initialLiftedState; | ||
var shouldRecomputeStates = true; | ||
var committedState = historyState.committedState; | ||
var stagedActions = historyState.stagedActions; | ||
var skippedActions = historyState.skippedActions; | ||
var computedStates = historyState.computedStates; | ||
var currentStateIndex = historyState.currentStateIndex; | ||
var timestamps = historyState.timestamps; | ||
var monitorState = liftedState.monitorState; | ||
var actionsById = liftedState.actionsById; | ||
var nextActionId = liftedState.nextActionId; | ||
var stagedActionIds = liftedState.stagedActionIds; | ||
var skippedActionIds = liftedState.skippedActionIds; | ||
var committedState = liftedState.committedState; | ||
var currentStateIndex = liftedState.currentStateIndex; | ||
var computedStates = liftedState.computedStates; | ||
switch (historyAction.type) { | ||
switch (liftedAction.type) { | ||
case ActionTypes.RESET: | ||
actionsById = { | ||
0: liftAction(INIT_ACTION) | ||
}; | ||
nextActionId = 1; | ||
stagedActionIds = [0]; | ||
skippedActionIds = []; | ||
committedState = initialCommittedState; | ||
stagedActions = [INIT_ACTION]; | ||
skippedActions = {}; | ||
currentStateIndex = 0; | ||
timestamps = [historyAction.timestamp]; | ||
break; | ||
case ActionTypes.COMMIT: | ||
actionsById = { | ||
0: liftAction(INIT_ACTION) | ||
}; | ||
nextActionId = 1; | ||
stagedActionIds = [0]; | ||
skippedActionIds = []; | ||
committedState = computedStates[currentStateIndex].state; | ||
stagedActions = [INIT_ACTION]; | ||
skippedActions = {}; | ||
currentStateIndex = 0; | ||
timestamps = [historyAction.timestamp]; | ||
break; | ||
case ActionTypes.ROLLBACK: | ||
stagedActions = [INIT_ACTION]; | ||
skippedActions = {}; | ||
actionsById = { | ||
0: liftAction(INIT_ACTION) | ||
}; | ||
nextActionId = 1; | ||
stagedActionIds = [0]; | ||
skippedActionIds = []; | ||
currentStateIndex = 0; | ||
timestamps = [historyAction.timestamp]; | ||
break; | ||
case ActionTypes.TOGGLE_ACTION: | ||
skippedActions = toggle(skippedActions, historyAction.index); | ||
var index = skippedActionIds.indexOf(liftedAction.id); | ||
if (index === -1) { | ||
skippedActionIds = [liftedAction.id].concat(skippedActionIds); | ||
} else { | ||
skippedActionIds = [].concat(skippedActionIds.slice(0, index), skippedActionIds.slice(index + 1)); | ||
} | ||
break; | ||
case ActionTypes.JUMP_TO_STATE: | ||
currentStateIndex = historyAction.index; | ||
currentStateIndex = liftedAction.index; | ||
// Optimization: we know the history has not changed. | ||
@@ -178,19 +208,16 @@ shouldRecomputeStates = false; | ||
case ActionTypes.SWEEP: | ||
stagedActions = stagedActions.filter(function (_, i) { | ||
return !skippedActions[i]; | ||
}); | ||
timestamps = timestamps.filter(function (_, i) { | ||
return !skippedActions[i]; | ||
}); | ||
skippedActions = {}; | ||
currentStateIndex = Math.min(currentStateIndex, stagedActions.length - 1); | ||
stagedActionIds = _lodashArrayDifference2['default'](stagedActionIds, skippedActionIds); | ||
skippedActionIds = []; | ||
currentStateIndex = Math.min(currentStateIndex, stagedActionIds.length - 1); | ||
break; | ||
case ActionTypes.PERFORM_ACTION: | ||
if (currentStateIndex === stagedActions.length - 1) { | ||
if (currentStateIndex === stagedActionIds.length - 1) { | ||
currentStateIndex++; | ||
} | ||
stagedActions = [].concat(stagedActions, [historyAction.action]); | ||
timestamps = [].concat(timestamps, [historyAction.timestamp]); | ||
var actionId = nextActionId++; | ||
// Mutation! This is the hottest path, and we optimize on purpose. | ||
// It is safe because we set a new key in a cache dictionary. | ||
actionsById[actionId] = liftedAction; | ||
stagedActionIds = [].concat(stagedActionIds, [actionId]); | ||
// Optimization: we know that the past has not changed. | ||
@@ -200,6 +227,24 @@ shouldRecomputeStates = false; | ||
var previousEntry = computedStates[computedStates.length - 1]; | ||
var nextEntry = computeNextEntry(reducer, historyAction.action, previousEntry.state, previousEntry.error); | ||
var nextEntry = computeNextEntry(reducer, liftedAction.action, previousEntry.state, previousEntry.error); | ||
computedStates = [].concat(computedStates, [nextEntry]); | ||
break; | ||
case ActionTypes.IMPORT_STATE: | ||
var _liftedAction$nextLiftedState = liftedAction.nextLiftedState; | ||
monitorState = _liftedAction$nextLiftedState.monitorState; | ||
actionsById = _liftedAction$nextLiftedState.actionsById; | ||
nextActionId = _liftedAction$nextLiftedState.nextActionId; | ||
stagedActionIds = _liftedAction$nextLiftedState.stagedActionIds; | ||
skippedActionIds = _liftedAction$nextLiftedState.skippedActionIds; | ||
committedState = _liftedAction$nextLiftedState.committedState; | ||
currentStateIndex = _liftedAction$nextLiftedState.currentStateIndex; | ||
computedStates = _liftedAction$nextLiftedState.computedStates; | ||
break; | ||
case '@@redux/INIT': | ||
// Always recompute states on hot reload and init. | ||
shouldRecomputeStates = true; | ||
break; | ||
default: | ||
// Optimization: a monitor action can't change history. | ||
shouldRecomputeStates = false; | ||
break; | ||
@@ -209,12 +254,16 @@ } | ||
if (shouldRecomputeStates) { | ||
computedStates = recomputeStates(reducer, committedState, stagedActions, skippedActions); | ||
computedStates = recomputeStates(reducer, committedState, actionsById, stagedActionIds, skippedActionIds); | ||
} | ||
monitorState = monitorReducer(monitorState, liftedAction); | ||
return { | ||
monitorState: monitorState, | ||
actionsById: actionsById, | ||
nextActionId: nextActionId, | ||
stagedActionIds: stagedActionIds, | ||
skippedActionIds: skippedActionIds, | ||
committedState: committedState, | ||
stagedActions: stagedActions, | ||
skippedActions: skippedActions, | ||
computedStates: computedStates, | ||
currentStateIndex: currentStateIndex, | ||
timestamps: timestamps | ||
computedStates: computedStates | ||
}; | ||
@@ -225,8 +274,7 @@ }; | ||
/** | ||
* Provides a view into the History state that matches the current app state. | ||
* Provides an app's view into the state of the lifted store. | ||
*/ | ||
function selectAppState(instrumentedState) { | ||
var _instrumentedState$historyState = instrumentedState.historyState; | ||
var computedStates = _instrumentedState$historyState.computedStates; | ||
var currentStateIndex = _instrumentedState$historyState.currentStateIndex; | ||
function unliftState(liftedState) { | ||
var computedStates = liftedState.computedStates; | ||
var currentStateIndex = liftedState.currentStateIndex; | ||
var state = computedStates[currentStateIndex].state; | ||
@@ -238,13 +286,13 @@ | ||
/** | ||
* Deinstruments the History store to act like the app's store. | ||
* Provides an app's view into the lifted store. | ||
*/ | ||
function selectAppStore(instrumentedStore, instrumentReducer) { | ||
function unliftStore(liftedStore, liftReducer) { | ||
var lastDefinedState = undefined; | ||
return _extends({}, instrumentedStore, { | ||
return _extends({}, liftedStore, { | ||
instrumentedStore: instrumentedStore, | ||
liftedStore: liftedStore, | ||
dispatch: function dispatch(action) { | ||
instrumentedStore.dispatch(ActionCreators.performAction(action)); | ||
liftedStore.dispatch(liftAction(action)); | ||
return action; | ||
@@ -254,3 +302,3 @@ }, | ||
getState: function getState() { | ||
var state = selectAppState(instrumentedStore.getState()); | ||
var state = unliftState(liftedStore.getState()); | ||
if (state !== undefined) { | ||
@@ -263,3 +311,3 @@ lastDefinedState = state; | ||
replaceReducer: function replaceReducer(nextReducer) { | ||
instrumentedStore.replaceReducer(instrumentReducer(nextReducer)); | ||
liftedStore.replaceReducer(liftReducer(nextReducer)); | ||
} | ||
@@ -270,3 +318,3 @@ }); | ||
/** | ||
* Redux History store enhancer. | ||
* Redux instrumentation store enhancer. | ||
*/ | ||
@@ -281,20 +329,10 @@ | ||
return function (reducer, initialState) { | ||
function instrumentReducer(r) { | ||
var historyReducer = createHistoryReducer(r, initialState); | ||
return function (_x2, action) { | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var historyState = _ref.historyState; | ||
var monitorState = _ref.monitorState; | ||
return { | ||
historyState: historyReducer(historyState, action), | ||
monitorState: monitorReducer(monitorState, action) | ||
}; | ||
}; | ||
function liftReducer(r) { | ||
return liftReducerWith(r, initialState, monitorReducer); | ||
} | ||
var instrumentedStore = createStore(instrumentReducer(reducer)); | ||
return selectAppStore(instrumentedStore, instrumentReducer); | ||
var liftedStore = createStore(liftReducer(reducer)); | ||
return unliftStore(liftedStore, liftReducer); | ||
}; | ||
}; | ||
} |
@@ -9,11 +9,15 @@ 'use strict'; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var identity = function identity(_) { | ||
return _; | ||
}; | ||
var _lodashObjectMapValues = require('lodash/object/mapValues'); | ||
var _lodashObjectMapValues2 = _interopRequireDefault(_lodashObjectMapValues); | ||
var _lodashUtilityIdentity = require('lodash/utility/identity'); | ||
var _lodashUtilityIdentity2 = _interopRequireDefault(_lodashUtilityIdentity); | ||
function persistState(sessionId) { | ||
var deserializeState = arguments.length <= 1 || arguments[1] === undefined ? identity : arguments[1]; | ||
var deserializeAction = arguments.length <= 2 || arguments[2] === undefined ? identity : arguments[2]; | ||
var deserializeState = arguments.length <= 1 || arguments[1] === undefined ? _lodashUtilityIdentity2['default'] : arguments[1]; | ||
var deserializeAction = arguments.length <= 2 || arguments[2] === undefined ? _lodashUtilityIdentity2['default'] : arguments[2]; | ||
@@ -28,16 +32,14 @@ if (!sessionId) { | ||
function deserialize(_ref) { | ||
var historyState = _ref.historyState; | ||
var rest = _objectWithoutProperties(_ref, ['historyState']); | ||
return _extends({}, rest, { | ||
historyState: _extends({}, historyState, { | ||
stagedActions: historyState.stagedActions.map(deserializeAction), | ||
committedState: deserializeState(historyState.committedState), | ||
computedStates: historyState.computedStates.map(function (computedState) { | ||
return _extends({}, computedState, { | ||
state: deserializeState(computedState.state) | ||
}); | ||
}) | ||
function deserialize(state) { | ||
return _extends({}, state, { | ||
actionsById: _lodashObjectMapValues2['default'](state.actionsById, function (liftedAction) { | ||
return _extends({}, liftedAction, { | ||
action: deserializeAction(liftedAction.action) | ||
}); | ||
}), | ||
committedState: deserializeState(state.committedState), | ||
computedStates: state.computedStates.map(function (computedState) { | ||
return _extends({}, computedState, { | ||
state: deserializeState(computedState.state) | ||
}); | ||
}) | ||
@@ -44,0 +46,0 @@ }); |
{ | ||
"name": "redux-devtools", | ||
"version": "3.0.0-alpha-7", | ||
"version": "3.0.0-beta-2", | ||
"description": "Redux DevTools with hot reloading and time travel", | ||
@@ -46,5 +46,5 @@ "main": "lib/index.js", | ||
"mocha-jsdom": "^1.0.0", | ||
"react": "^0.14.0-rc1", | ||
"react-addons-test-utils": "^0.14.0-rc1", | ||
"react-dom": "^0.14.0-rc1", | ||
"react": "^0.14.0", | ||
"react-addons-test-utils": "^0.14.0", | ||
"react-dom": "^0.14.0", | ||
"rimraf": "^2.3.4", | ||
@@ -54,8 +54,10 @@ "webpack": "^1.11.0" | ||
"peerDependencies": { | ||
"redux": "^3.0.0" | ||
"redux": "^3.0.0", | ||
"react": "^0.14.0" | ||
}, | ||
"dependencies": { | ||
"react-redux": "^3.0.0", | ||
"lodash": "^3.10.1", | ||
"react-redux": "^4.0.0", | ||
"redux": "^3.0.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27276
0
5
14
402
+ Addedlodash@^3.10.1
+ Addedacorn@5.7.4(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedasap@2.0.6(transitive)
+ Addedast-types@0.9.6(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase62@1.2.8(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcommoner@0.10.8(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-js@1.2.7(transitive)
+ Addedcreate-react-class@15.7.0(transitive)
+ Addeddefined@1.0.1(transitive)
+ Addeddetective@4.7.1(transitive)
+ Addedenvify@3.4.1(transitive)
+ Addedesprima@3.1.3(transitive)
+ Addedesprima-fb@15001.1.0-dev-harmony-fb(transitive)
+ Addedfbjs@0.6.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhoist-non-react-statics@3.3.2(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjstransform@11.0.3(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedobject-assign@2.1.14.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedpromise@7.3.1(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedq@1.5.1(transitive)
+ Addedreact@0.14.10(transitive)
+ Addedreact-is@16.13.1(transitive)
+ Addedreact-redux@4.4.10(transitive)
+ Addedrecast@0.11.23(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsource-map@0.4.40.5.7(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedua-parser-js@0.7.39(transitive)
+ Addedwhatwg-fetch@0.9.0(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedhoist-non-react-statics@1.2.0(transitive)
- Removedreact-redux@3.1.2(transitive)
Updatedreact-redux@^4.0.0