redux-devtools
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -35,5 +35,2 @@ 'use strict'; | ||
})(Monitor); | ||
var enhancer = (0, _instrument2.default)(function (state, action) { | ||
return Monitor.update(monitorProps, state, action); | ||
}); | ||
@@ -79,5 +76,7 @@ return _temp = _class = function (_Component) { | ||
store: _react.PropTypes.object | ||
}, _class.instrument = function () { | ||
return enhancer; | ||
}, _class.instrument = function (options) { | ||
return (0, _instrument2.default)(function (state, action) { | ||
return Monitor.update(monitorProps, state, action); | ||
}, options); | ||
}, _temp; | ||
} |
@@ -15,2 +15,6 @@ 'use strict'; | ||
var _union = require('lodash/union'); | ||
var _union2 = _interopRequireDefault(_union); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -25,2 +29,3 @@ | ||
TOGGLE_ACTION: 'TOGGLE_ACTION', | ||
SET_ACTIONS_ACTIVE: 'SET_ACTIONS_ACTIVE', | ||
JUMP_TO_STATE: 'JUMP_TO_STATE', | ||
@@ -55,2 +60,7 @@ IMPORT_STATE: 'IMPORT_STATE' | ||
}, | ||
setActionsActive: function setActionsActive(start, end) { | ||
var active = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; | ||
return { type: ActionTypes.SET_ACTIONS_ACTIVE, start: start, end: end, active: active }; | ||
}, | ||
jumpToState: function jumpToState(index) { | ||
@@ -137,3 +147,3 @@ return { type: ActionTypes.JUMP_TO_STATE, index: index }; | ||
*/ | ||
function liftReducerWith(reducer, initialCommittedState, monitorReducer) { | ||
function liftReducerWith(reducer, initialCommittedState, monitorReducer, options) { | ||
var initialLiftedState = { | ||
@@ -165,6 +175,30 @@ monitorState: monitorReducer(undefined, {}), | ||
function commitExcessActions(n) { | ||
// Auto-commits n-number of excess actions. | ||
var excess = n; | ||
var idsToDelete = stagedActionIds.slice(1, excess + 1); | ||
for (var i = 0; i < idsToDelete.length; i++) { | ||
if (computedStates[i + 1].error) { | ||
// Stop if error is found. Commit actions up to error. | ||
excess = i; | ||
idsToDelete = stagedActionIds.slice(1, excess + 1); | ||
break; | ||
} else { | ||
delete actionsById[idsToDelete[i]]; | ||
} | ||
} | ||
skippedActionIds = skippedActionIds.filter(function (id) { | ||
return idsToDelete.indexOf(id) === -1; | ||
}); | ||
stagedActionIds = [0].concat(stagedActionIds.slice(excess + 1)); | ||
committedState = computedStates[excess].state; | ||
computedStates = computedStates.slice(excess); | ||
currentStateIndex = currentStateIndex > excess ? currentStateIndex - excess : 0; | ||
} | ||
// By default, agressively recompute every state whatever happens. | ||
// This has O(n) performance, so we'll override this to a sensible | ||
// value whenever we feel like we don't have to recompute the states. | ||
var minInvalidatedStateIndex = 0; | ||
@@ -232,2 +266,23 @@ | ||
} | ||
case ActionTypes.SET_ACTIONS_ACTIVE: | ||
{ | ||
// Toggle whether an action with given ID is skipped. | ||
// Being skipped means it is a no-op during the computation. | ||
var start = liftedAction.start; | ||
var end = liftedAction.end; | ||
var active = liftedAction.active; | ||
var actionIds = []; | ||
for (var i = start; i < end; i++) { | ||
actionIds.push(i); | ||
}if (active) { | ||
skippedActionIds = (0, _difference2.default)(skippedActionIds, actionIds); | ||
} else { | ||
skippedActionIds = (0, _union2.default)(skippedActionIds, actionIds); | ||
} | ||
// Optimization: we know history before this action hasn't changed | ||
minInvalidatedStateIndex = stagedActionIds.indexOf(start); | ||
break; | ||
} | ||
case ActionTypes.JUMP_TO_STATE: | ||
@@ -252,2 +307,7 @@ { | ||
{ | ||
// Auto-commit as new actions come in. | ||
if (options.maxAge && stagedActionIds.length === options.maxAge) { | ||
commitExcessActions(1); | ||
} | ||
if (currentStateIndex === stagedActionIds.length - 1) { | ||
@@ -285,2 +345,13 @@ currentStateIndex++; | ||
minInvalidatedStateIndex = 0; | ||
if (options.maxAge && stagedActionIds.length > options.maxAge) { | ||
// States must be recomputed before committing excess. | ||
computedStates = recomputeStates(computedStates, minInvalidatedStateIndex, reducer, committedState, actionsById, stagedActionIds, skippedActionIds); | ||
commitExcessActions(stagedActionIds.length - options.maxAge); | ||
// Avoid double computation. | ||
minInvalidatedStateIndex = Infinity; | ||
} | ||
break; | ||
@@ -357,2 +428,3 @@ } | ||
} : arguments[0]; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -369,3 +441,3 @@ return function (createStore) { | ||
} | ||
return liftReducerWith(r, initialState, monitorReducer); | ||
return liftReducerWith(r, initialState, monitorReducer, options); | ||
} | ||
@@ -372,0 +444,0 @@ |
{ | ||
"name": "redux-devtools", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Redux DevTools with hot reloading and time travel", | ||
@@ -61,3 +61,3 @@ "main": "lib/index.js", | ||
"redux": "^3.0.0", | ||
"react": "^0.14.0" | ||
"react": "^0.14.0 || ^15.0.0-rc.1" | ||
}, | ||
@@ -64,0 +64,0 @@ "dependencies": { |
@@ -35,2 +35,4 @@ Redux DevTools | ||
If you came here looking for what do the “Reset”, “Revert”, “Sweep” or “Commit” buttons do, check out [the `LogMonitor` documentation](https://github.com/gaearon/redux-devtools-log-monitor/blob/master/README.md#features). | ||
### Chrome Extension | ||
@@ -96,2 +98,6 @@ | ||
#### [Inspector](https://github.com/alexkuz/redux-devtools-inspector) | ||
![](http://i.imgur.com/fYh8fk5.gif) | ||
#### [Diff Monitor](https://github.com/whetstone/redux-devtools-diff-monitor) | ||
@@ -115,2 +121,6 @@ | ||
#### [Dispatch](https://github.com/YoruNoHikage/redux-devtools-dispatch) | ||
![redux-devtools-dispatch](https://cloud.githubusercontent.com/assets/969003/12874321/2c3624ec-cdd2-11e5-9856-fd7e24efb8d5.gif) | ||
#### Keep them coming! | ||
@@ -117,0 +127,0 @@ |
@@ -10,5 +10,2 @@ import React, { Children, Component, PropTypes } from 'react'; | ||
const ConnectedMonitor = connect(state => state)(Monitor); | ||
const enhancer = instrument((state, action) => | ||
Monitor.update(monitorProps, state, action) | ||
); | ||
@@ -24,3 +21,6 @@ return class DevTools extends Component { | ||
static instrument = () => enhancer; | ||
static instrument = (options) => instrument( | ||
(state, action) => Monitor.update(monitorProps, state, action), | ||
options | ||
); | ||
@@ -27,0 +27,0 @@ constructor(props, context) { |
import difference from 'lodash/difference'; | ||
import union from 'lodash/union'; | ||
@@ -10,2 +11,3 @@ export const ActionTypes = { | ||
TOGGLE_ACTION: 'TOGGLE_ACTION', | ||
SET_ACTIONS_ACTIVE: 'SET_ACTIONS_ACTIVE', | ||
JUMP_TO_STATE: 'JUMP_TO_STATE', | ||
@@ -49,2 +51,6 @@ IMPORT_STATE: 'IMPORT_STATE' | ||
setActionsActive(start, end, active=true) { | ||
return { type: ActionTypes.SET_ACTIONS_ACTIVE, start, end, active }; | ||
}, | ||
jumpToState(index) { | ||
@@ -143,3 +149,3 @@ return { type: ActionTypes.JUMP_TO_STATE, index }; | ||
*/ | ||
function liftReducerWith(reducer, initialCommittedState, monitorReducer) { | ||
function liftReducerWith(reducer, initialCommittedState, monitorReducer, options) { | ||
const initialLiftedState = { | ||
@@ -171,2 +177,27 @@ monitorState: monitorReducer(undefined, {}), | ||
function commitExcessActions(n) { | ||
// Auto-commits n-number of excess actions. | ||
let excess = n; | ||
let idsToDelete = stagedActionIds.slice(1, excess + 1); | ||
for (let i = 0; i < idsToDelete.length; i++) { | ||
if (computedStates[i + 1].error) { | ||
// Stop if error is found. Commit actions up to error. | ||
excess = i; | ||
idsToDelete = stagedActionIds.slice(1, excess + 1); | ||
break; | ||
} else { | ||
delete actionsById[idsToDelete[i]]; | ||
} | ||
} | ||
skippedActionIds = skippedActionIds.filter(id => idsToDelete.indexOf(id) === -1); | ||
stagedActionIds = [0, ...stagedActionIds.slice(excess + 1)]; | ||
committedState = computedStates[excess].state; | ||
computedStates = computedStates.slice(excess); | ||
currentStateIndex = currentStateIndex > excess | ||
? currentStateIndex - excess | ||
: 0; | ||
} | ||
// By default, agressively recompute every state whatever happens. | ||
@@ -226,2 +257,18 @@ // This has O(n) performance, so we'll override this to a sensible | ||
} | ||
case ActionTypes.SET_ACTIONS_ACTIVE: { | ||
// Toggle whether an action with given ID is skipped. | ||
// Being skipped means it is a no-op during the computation. | ||
const { start, end, active } = liftedAction; | ||
const actionIds = []; | ||
for (let i = start; i < end; i++) actionIds.push(i); | ||
if (active) { | ||
skippedActionIds = difference(skippedActionIds, actionIds); | ||
} else { | ||
skippedActionIds = union(skippedActionIds, actionIds); | ||
} | ||
// Optimization: we know history before this action hasn't changed | ||
minInvalidatedStateIndex = stagedActionIds.indexOf(start); | ||
break; | ||
} | ||
case ActionTypes.JUMP_TO_STATE: { | ||
@@ -243,2 +290,7 @@ // Without recomputing anything, move the pointer that tell us | ||
case ActionTypes.PERFORM_ACTION: { | ||
// Auto-commit as new actions come in. | ||
if (options.maxAge && stagedActionIds.length === options.maxAge) { | ||
commitExcessActions(1); | ||
} | ||
if (currentStateIndex === stagedActionIds.length - 1) { | ||
@@ -273,2 +325,21 @@ currentStateIndex++; | ||
minInvalidatedStateIndex = 0; | ||
if (options.maxAge && stagedActionIds.length > options.maxAge) { | ||
// States must be recomputed before committing excess. | ||
computedStates = recomputeStates( | ||
computedStates, | ||
minInvalidatedStateIndex, | ||
reducer, | ||
committedState, | ||
actionsById, | ||
stagedActionIds, | ||
skippedActionIds | ||
); | ||
commitExcessActions(stagedActionIds.length - options.maxAge); | ||
// Avoid double computation. | ||
minInvalidatedStateIndex = Infinity; | ||
} | ||
break; | ||
@@ -349,3 +420,3 @@ } | ||
*/ | ||
export default function instrument(monitorReducer = () => null) { | ||
export default function instrument(monitorReducer = () => null, options = {}) { | ||
return createStore => (reducer, initialState, enhancer) => { | ||
@@ -365,3 +436,3 @@ | ||
} | ||
return liftReducerWith(r, initialState, monitorReducer); | ||
return liftReducerWith(r, initialState, monitorReducer, options); | ||
} | ||
@@ -368,0 +439,0 @@ |
48916
1051
130