Skip to content

Commit

Permalink
Debounce select topic action
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasnordquist committed Jan 25, 2019
1 parent 98369b2 commit 697b57a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"electron-nucleus": "^1.11.0",
"electron-telemetry": "git+https://github.com/thomasnordquist/electron-telemetry.git",
"html-webpack-plugin": "^4.0.0-beta.5",
"lodash.debounce": "^4.0.8",
"number-abbreviate": "^2.0.0",
"react": "^16.8.0-alpha.1",
"react-dom": "^16.7.0",
Expand Down
7 changes: 6 additions & 1 deletion app/src/actions/Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { Dispatch, AnyAction } from 'redux'
import { setTopic } from './Publish'
import { TopicViewModel } from '../TopicViewModel'
import { batchActions } from 'redux-batched-actions'
const debounce = require('lodash.debounce')

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
if (selectedTopic === topic) {
return
Expand Down Expand Up @@ -36,7 +41,7 @@ export const selectTopic = (topic: q.TreeNode<TopicViewModel>) => (dispatch: Dis
} else {
dispatch(selectTreeTopicDispatch)
}
}
}, 70)

export const showTree = (tree?: q.Tree<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState): AnyAction => {
const visibleTree = getState().tree.tree
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/Tree/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class TreeNode extends React.Component<Props, State> {

private setHover = debounce((hover: boolean) => {
this.setState({ mouseOver: hover })
}, 5)
}, 45)

private didClickNode = (event: React.MouseEvent) => {
event.stopPropagation()
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 697b57a

Please sign in to comment.