Skip to content
Snippets Groups Projects
Commit 0e442aae authored by DD Liu's avatar DD Liu
Browse files

Revert

parent 08f5b6c7
No related branches found
No related tags found
No related merge requests found
......@@ -32,8 +32,6 @@ const vmListenerHOC = function (WrappedComponent) {
this.props.vm.on('targetsUpdate', this.props.onTargetsUpdate);
this.props.vm.on('SPRITE_INFO_REPORT', this.props.onSpriteInfoReport);
this.props.vm.on('MONITORS_UPDATE', this.props.onMonitorsUpdate);
this.props.vm.on('MONITORS_REMOVED', this.props.onMonitorsRemoved);
this.props.vm.on('MONITORS_ADDED', this.props.onMonitorsAdded);
}
componentDidMount () {
if (this.props.attachKeyboardEvents) {
......@@ -81,9 +79,7 @@ const vmListenerHOC = function (WrappedComponent) {
onKeyDown,
onKeyUp,
onSpriteInfoReport,
onMonitorsAdded,
onMonitorsUpdate,
onMonitorsRemoved,
onTargetsUpdate,
/* eslint-enable no-unused-vars */
...props
......@@ -95,8 +91,6 @@ const vmListenerHOC = function (WrappedComponent) {
attachKeyboardEvents: PropTypes.bool,
onKeyDown: PropTypes.func,
onKeyUp: PropTypes.func,
onMonitorsAdded: PropTypes.func,
onMonitorsRemoved: PropTypes.func,
onMonitorsUpdate: PropTypes.func,
onSpriteInfoReport: PropTypes.func,
onTargetsUpdate: PropTypes.func,
......@@ -117,14 +111,8 @@ const vmListenerHOC = function (WrappedComponent) {
onSpriteInfoReport: spriteInfo => {
dispatch(targets.updateTarget(spriteInfo));
},
onMonitorsAdded: monitorList => {
dispatch(monitors.addMonitors(monitorList));
},
onMonitorsUpdate: monitorList => {
dispatch(monitors.updateMonitors(monitorList));
},
onMonitorsRemoved: monitorList => {
dispatch(monitors.removeMonitors(monitorList));
}
});
return connect(
......
const UPDATE_MONITORS = 'scratch-gui/monitors/UPDATE_MONITORS';
const REMOVE_MONITORS = 'scratch-gui/monitors/REMOVE_MONITORS';
const ADD_MONITORS = 'scratch-gui/monitors/ADD_MONITORS';
const initialState = [];
const reducer = function (state, action) {
if (typeof state === 'undefined') state = initialState;
let newState;
switch (action.type) {
case ADD_MONITORS:
for (let i = 0; i < action.monitors.length; i++) {
for (let j = 0; j < state.length; j++) {
if (action.monitors[i].id === state[j].id) {
// If the ID is already in the list, return instead of adding
// a duplicate to remain idempotent
return state;
}
}
}
return [...state, ...action.monitors];
// Adds or updates monitors
case UPDATE_MONITORS:
newState = [...state];
for (let i = 0; i < action.monitors.length; i++) {
for (let j = 0; j < state.length; j++) {
if (action.monitors[i].id === state[j].id) {
newState[j] = Object.assign({}, newState[j], action.monitors[i]);
continue;
}
}
}
return newState;
// Removes monitors
case REMOVE_MONITORS:
newState = [...state];
for (let i = 0; i < action.monitors.length; i++) {
// Move backwards to keep indices aligned
for (let j = state.length - 1; j >= 0; j--) {
if (action.monitors[i].id === state[j].id) {
newState.splice(j, 1);
continue;
}
}
}
return newState;
return [...action.monitors];
default:
return state;
}
......@@ -59,24 +22,4 @@ reducer.updateMonitors = function (monitors) {
};
};
reducer.addMonitors = function (monitors) {
return {
type: ADD_MONITORS,
monitors: monitors,
meta: {
throttle: 30
}
};
};
reducer.removeMonitors = function (monitors) {
return {
type: REMOVE_MONITORS,
monitors: monitors,
meta: {
throttle: 30
}
};
};
module.exports = reducer;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment