Socket
Socket
Sign inDemoInstall

redux-devtools

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-devtools - npm Package Compare versions

Comparing version 3.0.0-alpha-7 to 3.0.0-beta-2

43

lib/createDevTools.js

@@ -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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc