redux-devtools-instrument
Advanced tools
Comparing version 1.9.3 to 1.9.4
@@ -8,3 +8,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -55,3 +55,3 @@ exports.liftAction = liftAction; | ||
var ActionCreators = exports.ActionCreators = { | ||
performAction: function performAction(action, shouldIncludeCallstack) { | ||
performAction: function performAction(action, trace, traceLimit, toExcludeFromTrace) { | ||
if (!(0, _isPlainObject2.default)(action)) { | ||
@@ -65,6 +65,31 @@ throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.'); | ||
return { | ||
type: ActionTypes.PERFORM_ACTION, action: action, timestamp: Date.now(), | ||
stack: shouldIncludeCallstack ? Error().stack : undefined | ||
}; | ||
var stack = void 0; | ||
if (trace) { | ||
var extraFrames = 0; | ||
if (typeof trace === 'function') { | ||
stack = trace(action); | ||
} else { | ||
var error = Error(); | ||
var prevStackTraceLimit = void 0; | ||
if (Error.captureStackTrace) { | ||
if (Error.stackTraceLimit < traceLimit) { | ||
prevStackTraceLimit = Error.stackTraceLimit; | ||
Error.stackTraceLimit = traceLimit; | ||
} | ||
Error.captureStackTrace(error, toExcludeFromTrace); | ||
} else { | ||
extraFrames = 3; | ||
} | ||
stack = error.stack; | ||
if (prevStackTraceLimit) Error.stackTraceLimit = prevStackTraceLimit; | ||
if (extraFrames || typeof Error.stackTraceLimit !== 'number' || Error.stackTraceLimit > traceLimit) { | ||
var frames = stack.split('\n'); | ||
if (frames.length > traceLimit) { | ||
stack = frames.slice(0, traceLimit + extraFrames + (frames[0] === 'Error' ? 1 : 0)).join('\n'); | ||
} | ||
} | ||
} | ||
} | ||
return { type: ActionTypes.PERFORM_ACTION, action: action, timestamp: Date.now(), stack: stack }; | ||
}, | ||
@@ -87,3 +112,3 @@ reset: function reset() { | ||
setActionsActive: function setActionsActive(start, end) { | ||
var active = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; | ||
var active = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
@@ -191,4 +216,4 @@ return { type: ActionTypes.SET_ACTIONS_ACTIVE, start: start, end: end, active: active }; | ||
*/ | ||
function liftAction(action, shouldIncludeCallstack) { | ||
return ActionCreators.performAction(action, shouldIncludeCallstack); | ||
function liftAction(action, trace, traceLimit, toExcludeFromTrace) { | ||
return ActionCreators.performAction(action, trace, traceLimit, toExcludeFromTrace); | ||
} | ||
@@ -217,16 +242,14 @@ | ||
return function (liftedState, liftedAction) { | ||
var _ref = liftedState || initialLiftedState; | ||
var _ref = liftedState || initialLiftedState, | ||
monitorState = _ref.monitorState, | ||
actionsById = _ref.actionsById, | ||
nextActionId = _ref.nextActionId, | ||
stagedActionIds = _ref.stagedActionIds, | ||
skippedActionIds = _ref.skippedActionIds, | ||
committedState = _ref.committedState, | ||
currentStateIndex = _ref.currentStateIndex, | ||
computedStates = _ref.computedStates, | ||
isLocked = _ref.isLocked, | ||
isPaused = _ref.isPaused; | ||
var monitorState = _ref.monitorState; | ||
var actionsById = _ref.actionsById; | ||
var nextActionId = _ref.nextActionId; | ||
var stagedActionIds = _ref.stagedActionIds; | ||
var skippedActionIds = _ref.skippedActionIds; | ||
var committedState = _ref.committedState; | ||
var currentStateIndex = _ref.currentStateIndex; | ||
var computedStates = _ref.computedStates; | ||
var isLocked = _ref.isLocked; | ||
var isPaused = _ref.isPaused; | ||
if (!liftedState) { | ||
@@ -402,21 +425,17 @@ // Prevent mutating initialLiftedState | ||
{ | ||
var _ret = function () { | ||
// Toggle whether an action with given ID is skipped. | ||
// Being skipped means it is a no-op during the computation. | ||
var actionId = liftedAction.id; | ||
// Toggle whether an action with given ID is skipped. | ||
// Being skipped means it is a no-op during the computation. | ||
var _actionId = liftedAction.id; | ||
var index = skippedActionIds.indexOf(actionId); | ||
if (index === -1) { | ||
skippedActionIds = [actionId].concat(skippedActionIds); | ||
} else { | ||
skippedActionIds = skippedActionIds.filter(function (id) { | ||
return id !== actionId; | ||
}); | ||
} | ||
// Optimization: we know history before this action hasn't changed | ||
minInvalidatedStateIndex = stagedActionIds.indexOf(actionId); | ||
return 'break'; | ||
}(); | ||
if (_ret === 'break') break; | ||
var index = skippedActionIds.indexOf(_actionId); | ||
if (index === -1) { | ||
skippedActionIds = [_actionId].concat(skippedActionIds); | ||
} else { | ||
skippedActionIds = skippedActionIds.filter(function (id) { | ||
return id !== _actionId; | ||
}); | ||
} | ||
// Optimization: we know history before this action hasn't changed | ||
minInvalidatedStateIndex = stagedActionIds.indexOf(_actionId); | ||
break; | ||
} | ||
@@ -427,5 +446,5 @@ case ActionTypes.SET_ACTIONS_ACTIVE: | ||
// Being skipped means it is a no-op during the computation. | ||
var start = liftedAction.start; | ||
var end = liftedAction.end; | ||
var active = liftedAction.active; | ||
var start = liftedAction.start, | ||
end = liftedAction.end, | ||
active = liftedAction.active; | ||
@@ -474,4 +493,4 @@ var actionIds = []; | ||
// Recompute actions in a new order. | ||
var _actionId = liftedAction.actionId; | ||
var idx = stagedActionIds.indexOf(_actionId); | ||
var _actionId2 = liftedAction.actionId; | ||
var idx = stagedActionIds.indexOf(_actionId2); | ||
// do nothing in case the action is already removed or trying to move the first action | ||
@@ -490,7 +509,7 @@ if (idx < 1) break; | ||
// move left | ||
stagedActionIds = [].concat(stagedActionIds.slice(0, newIdx), [_actionId], stagedActionIds.slice(newIdx, idx), stagedActionIds.slice(idx + 1)); | ||
stagedActionIds = [].concat(stagedActionIds.slice(0, newIdx), [_actionId2], stagedActionIds.slice(newIdx, idx), stagedActionIds.slice(idx + 1)); | ||
minInvalidatedStateIndex = newIdx; | ||
} else if (diff < 0) { | ||
// move right | ||
stagedActionIds = [].concat(stagedActionIds.slice(0, idx), stagedActionIds.slice(idx + 1, newIdx), [_actionId], stagedActionIds.slice(newIdx)); | ||
stagedActionIds = [].concat(stagedActionIds.slice(0, idx), stagedActionIds.slice(idx + 1, newIdx), [_actionId2], stagedActionIds.slice(newIdx)); | ||
minInvalidatedStateIndex = idx; | ||
@@ -514,3 +533,3 @@ } | ||
liftedAction.nextLiftedState.forEach(function (action) { | ||
actionsById[nextActionId] = liftAction(action, options.shouldIncludeCallstack); | ||
actionsById[nextActionId] = liftAction(action, options.trace || options.shouldIncludeCallstack); | ||
stagedActionIds.push(nextActionId); | ||
@@ -593,4 +612,4 @@ nextActionId++; | ||
function unliftState(liftedState) { | ||
var computedStates = liftedState.computedStates; | ||
var currentStateIndex = liftedState.currentStateIndex; | ||
var computedStates = liftedState.computedStates, | ||
currentStateIndex = liftedState.currentStateIndex; | ||
var state = computedStates[currentStateIndex].state; | ||
@@ -608,5 +627,5 @@ | ||
var lastDefinedState = void 0; | ||
var shouldIncludeCallstack = options.shouldIncludeCallstack; | ||
var trace = options.trace || options.shouldIncludeCallstack; | ||
var traceLimit = options.traceLimit || 10; | ||
function getState() { | ||
@@ -620,2 +639,7 @@ var state = unliftState(liftedStore.getState()); | ||
function dispatch(action) { | ||
liftedStore.dispatch(liftAction(action, trace, traceLimit, dispatch)); | ||
return action; | ||
} | ||
return _extends({}, liftedStore, (_extends3 = { | ||
@@ -625,8 +649,4 @@ | ||
dispatch: function dispatch(action) { | ||
liftedStore.dispatch(liftAction(action, shouldIncludeCallstack)); | ||
return action; | ||
}, | ||
dispatch: dispatch, | ||
getState: getState, | ||
@@ -662,6 +682,6 @@ | ||
function instrument() { | ||
var monitorReducer = arguments.length <= 0 || arguments[0] === undefined ? function () { | ||
var monitorReducer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () { | ||
return null; | ||
} : arguments[0]; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -668,0 +688,0 @@ if (typeof options.maxAge === 'number' && options.maxAge < 2) { |
{ | ||
"name": "redux-devtools-instrument", | ||
"version": "1.9.3", | ||
"version": "1.9.4", | ||
"description": "Redux DevTools instrumentation", | ||
@@ -13,3 +13,4 @@ "main": "lib/instrument.js", | ||
"test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive", | ||
"prepublish": "npm run lint && npm run test && npm run clean && npm run build" | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm run lint && npm run test && npm run clean && npm run build" | ||
}, | ||
@@ -22,3 +23,3 @@ "files": [ | ||
"type": "git", | ||
"url": "https://github.com/zalmoxisus/redux-devtools-instrument.git" | ||
"url": "https://github.com/reduxjs/redux-devtools.git" | ||
}, | ||
@@ -36,5 +37,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/zalmoxisus/redux-devtools-instrument/issues" | ||
"url": "https://github.com/reduxjs/redux-devtools/issues" | ||
}, | ||
"homepage": "https://github.com/zalmoxisus/redux-devtools-instrument", | ||
"homepage": "https://github.com/reduxjs/redux-devtools", | ||
"devDependencies": { | ||
@@ -41,0 +42,0 @@ "babel-cli": "^6.3.17", |
Redux DevTools Instrumentation | ||
============================== | ||
Redux enhancer used along with [Redux DevTools](https://github.com/gaearon/redux-devtools) or [Remote Redux DevTools](https://github.com/zalmoxisus/remote-redux-devtools). | ||
Redux enhancer used along with [Redux DevTools](https://github.com/reduxjs/redux-devtools) or [Remote Redux DevTools](https://github.com/zalmoxisus/remote-redux-devtools). | ||
@@ -53,3 +53,4 @@ ### Installation | ||
- **shouldHotReload** *boolean* - if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Default to `true`. | ||
- **shouldIncludeCallstack** *boolean* - if set to `true`, will include callstack for every dispatched action. Default to `false`. | ||
- **trace** *boolean* or *function* - if set to `true`, will include stack trace for every dispatched action. You can use a function (with action object as argument) which should return `new Error().stack` string, getting the stack outside of reducers. Default to `false`. | ||
- **traceLimit** *number* - maximum stack trace frames to be stored (in case `trace` option was provided as `true`). By default it's `10`. If `trace` option is a function, `traceLimit` will have no effect, that should be handled there like so: `trace: () => new Error().stack.split('\n').slice(0, limit+1).join('\n')` (`+1` is needed for Chrome where's an extra 1st frame for `Error\n`). | ||
@@ -56,0 +57,0 @@ ### License |
@@ -26,3 +26,3 @@ import difference from 'lodash/difference'; | ||
export const ActionCreators = { | ||
performAction(action, shouldIncludeCallstack) { | ||
performAction(action, trace, traceLimit, toExcludeFromTrace) { | ||
if (!isPlainObject(action)) { | ||
@@ -42,6 +42,31 @@ throw new Error( | ||
return { | ||
type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now(), | ||
stack: shouldIncludeCallstack ? Error().stack : undefined | ||
}; | ||
let stack; | ||
if (trace) { | ||
let extraFrames = 0; | ||
if (typeof trace === 'function') { | ||
stack = trace(action); | ||
} else { | ||
const error = Error(); | ||
let prevStackTraceLimit; | ||
if (Error.captureStackTrace) { | ||
if (Error.stackTraceLimit < traceLimit) { | ||
prevStackTraceLimit = Error.stackTraceLimit; | ||
Error.stackTraceLimit = traceLimit; | ||
} | ||
Error.captureStackTrace(error, toExcludeFromTrace); | ||
} else { | ||
extraFrames = 3; | ||
} | ||
stack = error.stack; | ||
if (prevStackTraceLimit) Error.stackTraceLimit = prevStackTraceLimit; | ||
if (extraFrames || typeof Error.stackTraceLimit !== 'number' || Error.stackTraceLimit > traceLimit) { | ||
const frames = stack.split('\n'); | ||
if (frames.length > traceLimit) { | ||
stack = frames.slice(0, traceLimit + extraFrames + (frames[0] === 'Error' ? 1 : 0)).join('\n'); | ||
} | ||
} | ||
} | ||
} | ||
return { type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now(), stack }; | ||
}, | ||
@@ -193,4 +218,4 @@ | ||
*/ | ||
export function liftAction(action, shouldIncludeCallstack) { | ||
return ActionCreators.performAction(action, shouldIncludeCallstack); | ||
export function liftAction(action, trace, traceLimit, toExcludeFromTrace) { | ||
return ActionCreators.performAction(action, trace, traceLimit, toExcludeFromTrace); | ||
} | ||
@@ -508,3 +533,3 @@ | ||
liftedAction.nextLiftedState.forEach(action => { | ||
actionsById[nextActionId] = liftAction(action, options.shouldIncludeCallstack); | ||
actionsById[nextActionId] = liftAction(action, options.trace || options.shouldIncludeCallstack); | ||
stagedActionIds.push(nextActionId); | ||
@@ -602,3 +627,4 @@ nextActionId++; | ||
let lastDefinedState; | ||
const { shouldIncludeCallstack } = options; | ||
const trace = options.trace || options.shouldIncludeCallstack; | ||
const traceLimit = options.traceLimit || 10; | ||
@@ -613,2 +639,7 @@ function getState() { | ||
function dispatch(action) { | ||
liftedStore.dispatch(liftAction(action, trace, traceLimit, dispatch)); | ||
return action; | ||
} | ||
return { | ||
@@ -619,6 +650,3 @@ ...liftedStore, | ||
dispatch(action) { | ||
liftedStore.dispatch(liftAction(action, shouldIncludeCallstack)); | ||
return action; | ||
}, | ||
dispatch, | ||
@@ -625,0 +653,0 @@ getState, |
54615
1270
59
5