redux-devtools-instrument
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -24,2 +24,10 @@ 'use strict'; | ||
var _isPlainObject = require('lodash/isPlainObject'); | ||
var _isPlainObject2 = _interopRequireDefault(_isPlainObject); | ||
var _symbolObservable = require('symbol-observable'); | ||
var _symbolObservable2 = _interopRequireDefault(_symbolObservable); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -44,5 +52,10 @@ | ||
performAction: function performAction(action) { | ||
if (!(0, _isPlainObject2.default)(action)) { | ||
throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.'); | ||
} | ||
if (typeof action.type === 'undefined') { | ||
throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?'); | ||
} | ||
return { type: ActionTypes.PERFORM_ACTION, action: action, timestamp: Date.now() }; | ||
@@ -166,15 +179,20 @@ }, | ||
*/ | ||
return function () { | ||
var liftedState = arguments.length <= 0 || arguments[0] === undefined ? initialLiftedState : arguments[0]; | ||
var liftedAction = arguments[1]; | ||
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; | ||
return function (liftedState, liftedAction) { | ||
var _ref = liftedState || initialLiftedState; | ||
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; | ||
if (!liftedState) { | ||
// Prevent mutating initialLiftedState | ||
actionsById = _extends({}, actionsById); | ||
} | ||
function commitExcessActions(n) { | ||
@@ -399,6 +417,16 @@ // Auto-commits n-number of excess actions. | ||
function unliftStore(liftedStore, liftReducer) { | ||
var _extends2; | ||
var lastDefinedState = void 0; | ||
return _extends({}, liftedStore, { | ||
function getState() { | ||
var state = unliftState(liftedStore.getState()); | ||
if (state !== undefined) { | ||
lastDefinedState = state; | ||
} | ||
return lastDefinedState; | ||
} | ||
return _extends({}, liftedStore, (_extends2 = { | ||
liftedStore: liftedStore, | ||
@@ -410,13 +438,28 @@ | ||
}, | ||
getState: function getState() { | ||
var state = unliftState(liftedStore.getState()); | ||
if (state !== undefined) { | ||
lastDefinedState = state; | ||
} | ||
return lastDefinedState; | ||
}, | ||
getState: getState, | ||
replaceReducer: function replaceReducer(nextReducer) { | ||
liftedStore.replaceReducer(liftReducer(nextReducer)); | ||
} | ||
}); | ||
}, _extends2[_symbolObservable2.default] = function () { | ||
return _extends({}, liftedStore[_symbolObservable2.default](), { | ||
subscribe: function subscribe(observer) { | ||
if ((typeof observer === 'undefined' ? 'undefined' : _typeof(observer)) !== 'object') { | ||
throw new TypeError('Expected the observer to be an object.'); | ||
} | ||
function observeState() { | ||
if (observer.next) { | ||
observer.next(getState()); | ||
} | ||
} | ||
observeState(); | ||
var unsubscribe = liftedStore.subscribe(observeState); | ||
return { unsubscribe: unsubscribe }; | ||
} | ||
}); | ||
}, _extends2)); | ||
} | ||
@@ -423,0 +466,0 @@ |
{ | ||
"name": "redux-devtools-instrument", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Redux DevTools instrumentation", | ||
@@ -50,8 +50,11 @@ "main": "lib/instrument.js", | ||
"mocha": "^2.2.5", | ||
"redux": "^3.0.0", | ||
"rimraf": "^2.3.4" | ||
"redux": "^3.5.2", | ||
"rimraf": "^2.3.4", | ||
"rxjs": "^5.0.0-beta.6", | ||
"webpack": "^1.11.0" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.2.0" | ||
"lodash": "^4.2.0", | ||
"symbol-observable": "^0.2.4" | ||
} | ||
} |
import difference from 'lodash/difference'; | ||
import union from 'lodash/union'; | ||
import isPlainObject from 'lodash/isPlainObject'; | ||
import $$observable from 'symbol-observable'; | ||
@@ -21,2 +23,9 @@ export const ActionTypes = { | ||
performAction(action) { | ||
if (!isPlainObject(action)) { | ||
throw new Error( | ||
'Actions must be plain objects. ' + | ||
'Use custom middleware for async actions.' | ||
); | ||
} | ||
if (typeof action.type === 'undefined') { | ||
@@ -28,2 +37,3 @@ throw new Error( | ||
} | ||
return { type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now() }; | ||
@@ -164,3 +174,3 @@ }, | ||
*/ | ||
return (liftedState = initialLiftedState, liftedAction) => { | ||
return (liftedState, liftedAction) => { | ||
let { | ||
@@ -175,4 +185,9 @@ monitorState, | ||
computedStates | ||
} = liftedState; | ||
} = liftedState || initialLiftedState; | ||
if (!liftedState) { | ||
// Prevent mutating initialLiftedState | ||
actionsById = { ...actionsById }; | ||
} | ||
function commitExcessActions(n) { | ||
@@ -390,2 +405,10 @@ // Auto-commits n-number of excess actions. | ||
function getState() { | ||
const state = unliftState(liftedStore.getState()); | ||
if (state !== undefined) { | ||
lastDefinedState = state; | ||
} | ||
return lastDefinedState; | ||
} | ||
return { | ||
@@ -401,12 +424,27 @@ ...liftedStore, | ||
getState() { | ||
const state = unliftState(liftedStore.getState()); | ||
if (state !== undefined) { | ||
lastDefinedState = state; | ||
} | ||
return lastDefinedState; | ||
}, | ||
getState, | ||
replaceReducer(nextReducer) { | ||
liftedStore.replaceReducer(liftReducer(nextReducer)); | ||
}, | ||
[$$observable]() { | ||
return { | ||
...liftedStore[$$observable](), | ||
subscribe(observer) { | ||
if (typeof observer !== 'object') { | ||
throw new TypeError('Expected the observer to be an object.'); | ||
} | ||
function observeState() { | ||
if (observer.next) { | ||
observer.next(getState()); | ||
} | ||
} | ||
observeState(); | ||
const unsubscribe = liftedStore.subscribe(observeState); | ||
return { unsubscribe }; | ||
} | ||
}; | ||
} | ||
@@ -413,0 +451,0 @@ }; |
36198
861
2
16
+ Addedsymbol-observable@^0.2.4
+ Addedsymbol-observable@0.2.4(transitive)