Skip to content
Snippets Groups Projects
Commit e0a9f0ea authored by Ray Schamp's avatar Ray Schamp
Browse files

Throttle actions coming in from the VM

These aren't necessary to update in realtime, so throttle them to once every 30ms
parent f695307d
No related branches found
No related tags found
No related merge requests found
const React = require('react'); const React = require('react');
const ReactDOM = require('react-dom'); const ReactDOM = require('react-dom');
const {Provider} = require('react-redux'); const {Provider} = require('react-redux');
const {createStore} = require('redux'); const {createStore, applyMiddleware} = require('redux');
const throttle = require('redux-throttle').default;
const GUI = require('./containers/gui.jsx'); const GUI = require('./containers/gui.jsx');
const log = require('./lib/log'); const log = require('./lib/log');
...@@ -63,7 +64,9 @@ App.propTypes = { ...@@ -63,7 +64,9 @@ App.propTypes = {
const appTarget = document.createElement('div'); const appTarget = document.createElement('div');
appTarget.className = styles.app; appTarget.className = styles.app;
document.body.appendChild(appTarget); document.body.appendChild(appTarget);
const store = createStore( const store = applyMiddleware(
throttle(300, {leading: true, trailing: true})
)(createStore)(
reducer, reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
); );
......
...@@ -55,19 +55,28 @@ const reducer = function (state, action) { ...@@ -55,19 +55,28 @@ const reducer = function (state, action) {
reducer.updateTarget = function (target) { reducer.updateTarget = function (target) {
return { return {
type: UPDATE_TARGET, type: UPDATE_TARGET,
target: target target: target,
meta: {
throttle: 30
}
}; };
}; };
reducer.updateTargets = function (targetList) { reducer.updateTargets = function (targetList) {
return { return {
type: UPDATE_TARGET_LIST, type: UPDATE_TARGET_LIST,
targets: targetList targets: targetList,
meta: {
throttle: 30
}
}; };
}; };
reducer.updateEditingTarget = function (editingTarget) { reducer.updateEditingTarget = function (editingTarget) {
return { return {
type: UPDATE_EDITING_TARGET, type: UPDATE_EDITING_TARGET,
target: editingTarget target: editingTarget,
meta: {
throttle: 30
}
}; };
}; };
module.exports = reducer; 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