Debounce select topic action

This commit is contained in:
Thomas Nordquist
2019-01-25 20:57:20 +01:00
parent 98369b278a
commit 697b57a141
5 changed files with 11 additions and 5 deletions

2
app/package-lock.json generated
View File

@@ -2301,7 +2301,7 @@
} }
}, },
"electron-telemetry": { "electron-telemetry": {
"version": "git+https://github.com/thomasnordquist/electron-telemetry.git#b6bd0bd6c0f84d387e1a0c970338517a78d67717", "version": "git+https://github.com/thomasnordquist/electron-telemetry.git#a58a28de84874b16fb3d60ae9e83f5a94d873353",
"from": "git+https://github.com/thomasnordquist/electron-telemetry.git", "from": "git+https://github.com/thomasnordquist/electron-telemetry.git",
"dev": true, "dev": true,
"requires": { "requires": {

View File

@@ -17,6 +17,7 @@
"electron-nucleus": "^1.11.0", "electron-nucleus": "^1.11.0",
"electron-telemetry": "git+https://github.com/thomasnordquist/electron-telemetry.git", "electron-telemetry": "git+https://github.com/thomasnordquist/electron-telemetry.git",
"html-webpack-plugin": "^4.0.0-beta.5", "html-webpack-plugin": "^4.0.0-beta.5",
"lodash.debounce": "^4.0.8",
"number-abbreviate": "^2.0.0", "number-abbreviate": "^2.0.0",
"react": "^16.8.0-alpha.1", "react": "^16.8.0-alpha.1",
"react-dom": "^16.7.0", "react-dom": "^16.7.0",

View File

@@ -5,8 +5,13 @@ import { Dispatch, AnyAction } from 'redux'
import { setTopic } from './Publish' import { setTopic } from './Publish'
import { TopicViewModel } from '../TopicViewModel' import { TopicViewModel } from '../TopicViewModel'
import { batchActions } from 'redux-batched-actions' import { batchActions } from 'redux-batched-actions'
const debounce = require('lodash.debounce')
export const selectTopic = (topic: q.TreeNode<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState) => { export const selectTopic = (topic: q.TreeNode<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState) => {
debouncedSelectTopic(topic, dispatch, getState)
}
const debouncedSelectTopic = debounce((topic: q.TreeNode<TopicViewModel>, dispatch: Dispatch<any>, getState: () => AppState) => {
const { selectedTopic } = getState().tree const { selectedTopic } = getState().tree
if (selectedTopic === topic) { if (selectedTopic === topic) {
return return
@@ -36,7 +41,7 @@ export const selectTopic = (topic: q.TreeNode<TopicViewModel>) => (dispatch: Dis
} else { } else {
dispatch(selectTreeTopicDispatch) dispatch(selectTreeTopicDispatch)
} }
} }, 70)
export const showTree = (tree?: q.Tree<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState): AnyAction => { export const showTree = (tree?: q.Tree<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState): AnyAction => {
const visibleTree = getState().tree.tree const visibleTree = getState().tree.tree

View File

@@ -225,7 +225,7 @@ class TreeNode extends React.Component<Props, State> {
private setHover = debounce((hover: boolean) => { private setHover = debounce((hover: boolean) => {
this.setState({ mouseOver: hover }) this.setState({ mouseOver: hover })
}, 5) }, 45)
private didClickNode = (event: React.MouseEvent) => { private didClickNode = (event: React.MouseEvent) => {
event.stopPropagation() event.stopPropagation()

4
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "MQTT-Explorer", "name": "MQTT-Explorer",
"version": "0.1.3", "version": "0.1.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -1281,7 +1281,7 @@
} }
}, },
"electron-telemetry": { "electron-telemetry": {
"version": "git+https://github.com/thomasnordquist/electron-telemetry.git#b6bd0bd6c0f84d387e1a0c970338517a78d67717", "version": "git+https://github.com/thomasnordquist/electron-telemetry.git#a58a28de84874b16fb3d60ae9e83f5a94d873353",
"from": "git+https://github.com/thomasnordquist/electron-telemetry.git", "from": "git+https://github.com/thomasnordquist/electron-telemetry.git",
"requires": { "requires": {
"@types/node": "^10.12.18", "@types/node": "^10.12.18",