Skip to content

Commit 65e1a39

Browse files
committed
debounce dispatch
1 parent d73b567 commit 65e1a39

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,17 @@ class MarkdownNoteDetail extends React.Component {
8989
}
9090

9191
save () {
92-
let { note, dispatch } = this.props
93-
94-
dispatch({
95-
type: 'UPDATE_NOTE',
96-
note: this.state.note
97-
})
92+
clearTimeout(this.saveQueue)
93+
this.saveQueue = setTimeout(() => {
94+
let { note, dispatch } = this.props
95+
dispatch({
96+
type: 'UPDATE_NOTE',
97+
note: this.state.note
98+
})
9899

99-
dataApi
100-
.updateNote(note.storage, note.folder, note.key, this.state.note)
100+
dataApi
101+
.updateNote(note.storage, note.folder, note.key, this.state.note)
102+
}, 1000)
101103
}
102104

103105
handleFolderChange (e) {

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,17 @@ class SnippetNoteDetail extends React.Component {
9999
}
100100

101101
save () {
102-
let { note, dispatch } = this.props
103-
104-
dispatch({
105-
type: 'UPDATE_NOTE',
106-
note: this.state.note
107-
})
102+
clearTimeout(this.saveQueue)
103+
this.saveQueue = setTimeout(() => {
104+
let { note, dispatch } = this.props
105+
dispatch({
106+
type: 'UPDATE_NOTE',
107+
note: this.state.note
108+
})
108109

109-
dataApi
110-
.updateNote(note.storage, note.folder, note.key, this.state.note)
110+
dataApi
111+
.updateNote(note.storage, note.folder, note.key, this.state.note)
112+
}, 1000)
111113
}
112114

113115
handleFolderChange (e) {

0 commit comments

Comments
 (0)