Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remote-redux-devtools

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remote-redux-devtools - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3-alpha1

134

lib/devTools.js

@@ -5,2 +5,4 @@ '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 _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -24,4 +26,6 @@

var ERROR = '@@remotedev/ERROR';
var monitorActions = [// To be skipped for relaying actions
'TOGGLE_ACTION', 'SWEEP', 'IMPORT_STATE', 'SET_ACTIONS_ACTIVE'];
'@@redux/INIT', 'TOGGLE_ACTION', 'SWEEP', 'IMPORT_STATE', 'SET_ACTIONS_ACTIVE'];

@@ -42,2 +46,3 @@ var instanceId = void 0;

var sendOn = void 0;
var sendOnError = void 0;
var sendTo = void 0;

@@ -50,18 +55,2 @@

function relay(type, state, action, nextActionId) {
if (filters && isFiltered(action)) return;
var message = {
type: type,
id: socket.id,
name: instanceName
};
if (state) message.payload = (0, _jsan.stringify)(state);
if (action) {
message.action = (0, _jsan.stringify)(action);
message.isExcess = isExcess;
}
if (nextActionId) message.nextActionId = (0, _jsan.stringify)(nextActionId);
socket.emit(socket.id ? 'log' : 'log-noid', message);
}
function filterStagedActions(state) {

@@ -86,2 +75,40 @@ if (!filters) return state;

function send() {
if (!instanceId) instanceId = socket && socket.id || Math.random().toString(36).substr(2);
try {
fetch(sendTo, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
type: 'STATE',
id: instanceId,
name: instanceName,
payload: (0, _jsan.stringify)(filterStagedActions(store.liftedStore.getState()))
})
}).catch(function (err) {
console.warn(err);
});
} catch (err) {
console.warn(err);
}
}
function relay(type, state, action, nextActionId) {
if (filters && isFiltered(action)) return;
var message = {
type: type,
id: socket.id,
name: instanceName
};
if (state) message.payload = (0, _jsan.stringify)(state);
if (action) {
message.action = (0, _jsan.stringify)(action);
message.isExcess = isExcess;
}
if (nextActionId) message.nextActionId = (0, _jsan.stringify)(nextActionId);
socket.emit(socket.id ? 'log' : 'log-noid', message);
}
function handleMessages(message) {

@@ -106,2 +133,32 @@ if (message.type === 'IMPORT' || message.type === 'SYNC' && socket.id && message.id !== socket.id) {

function sendError(errorAction) {
store.dispatch(errorAction);
if (!started) send();
}
function catchErrors() {
if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && _typeof(window.onerror) === 'object') {
window.onerror = function (message, url, lineNo, columnNo, error) {
var errorAction = { type: ERROR, message: message, url: url, lineNo: lineNo, columnNo: columnNo };
if (error && error.stack) errorAction.stack = error.stack;
sendError(errorAction);
return false;
};
} else if (typeof global !== 'undefined' && global.ErrorUtils) {
global.ErrorUtils.setGlobalHandler(function (error, isFatal) {
sendError({ type: ERROR, error: error, isFatal: isFatal });
});
}
if ((typeof console === 'undefined' ? 'undefined' : _typeof(console)) === 'object' && typeof console.error === 'function' && !console.beforeRemotedev) {
console.beforeRemotedev = console.error.bind(console);
console.error = function () {
var message = arguments[0];
var stack = message && message.stack;
sendError({ type: ERROR, message: message, stack: stack });
console.beforeRemotedev.apply(null, arguments);
};
}
}
function str2array(str) {

@@ -127,6 +184,8 @@ return typeof str === 'string' ? [str] : str && str.length;

sendOn = str2array(options.sendOn);
if (sendOn) {
sendOnError = options.sendOnError;
if (sendOn || sendOnError) {
sendTo = options.sendTo || (socketOptions.secure ? 'https' : 'http') + '://' + socketOptions.hostname + ':' + socketOptions.port;
instanceId = options.id;
}
if (sendOnError === 1) catchErrors();
}

@@ -166,24 +225,2 @@

function send() {
if (!instanceId) instanceId = socket && socket.id || Math.random().toString(36).substr(2);
try {
fetch(sendTo, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
type: 'STATE',
id: instanceId,
name: instanceName,
payload: (0, _jsan.stringify)(filterStagedActions(store.liftedStore.getState()))
})
}).catch(function (err) {
console.warn(err);
});
} catch (err) {
console.warn(err);
}
}
function async(fn) {

@@ -193,2 +230,12 @@ setTimeout(fn, 0);

function checkForReducerErrors() {
var liftedState = arguments.length <= 0 || arguments[0] === undefined ? store.liftedStore.getState() : arguments[0];
if (liftedState.computedStates[liftedState.currentStateIndex].error) {
if (started) relay('STATE', filterStagedActions(liftedState));else send();
return true;
}
return false;
}
function monitorReducer() {

@@ -198,6 +245,6 @@ var state = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

if (action.action) {
lastAction = action.type;
if (!started && sendOnError === 2 && store.liftedStore) async(checkForReducerErrors);else if (action.action) {
if (startOn && !started && startOn.indexOf(action.action.type) !== -1) async(start);else if (stopOn && started && stopOn.indexOf(action.action.type) !== -1) async(stop);else if (sendOn && !started && sendOn.indexOf(action.action.type) !== -1) async(send);
}
lastAction = action.type;
return state;

@@ -207,5 +254,8 @@ }

function handleChange(state, liftedState, maxAge) {
if (checkForReducerErrors(liftedState)) return;
var nextActionId = liftedState.nextActionId;
var liftedAction = liftedState.actionsById[nextActionId - 1];
var action = liftedAction.action;
if (action.type === '@@INIT') {

@@ -212,0 +262,0 @@ relay('INIT', state, { timestamp: Date.now() });

{
"name": "remote-redux-devtools",
"version": "0.3.2",
"version": "0.3.3-alpha1",
"description": "Relay Redux actions to remote Redux DevTools.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -72,2 +72,3 @@ Remote Redux DevTools

`sendOn` | *String* or *Array of strings* indicating an action or a list of actions, which should trigger sending the history to the monitor (without starting it). *Note*: when using it, add a `fetch` polyfill if needed.
`sendOnError` | *Numeric* code: `0` - disabled (default), `1` - send all uncaught exception messages (for browser and React Native), `2` - send only reducers error messages.
`sendTo` | *String* url of the monitor to send the history when `sendOn` is triggered. By default is `${secure ? 'https' : 'http'}://${hostname}:${port}`.

@@ -74,0 +75,0 @@ `id` | *String* to identify the instance when sending the history triggered by `sendOn`. You can use, for example, user id here, to know who sent the data.

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