diff --git a/internal_packages/undo-redo/lib/undo-redo-component.cjsx b/internal_packages/undo-redo/lib/undo-redo-component.cjsx
index e5cb773e2..5189de65b 100644
--- a/internal_packages/undo-redo/lib/undo-redo-component.cjsx
+++ b/internal_packages/undo-redo/lib/undo-redo-component.cjsx
@@ -15,66 +15,66 @@ class UndoRedoComponent extends React.Component
@containerRequired: false
constructor: (@props) ->
- @state = @_getStateFromStores()
@_timeout = null
-
- _onChange: =>
- @setState(@_getStateFromStores(), =>
- @_setNewTimeout())
+ @state = @_getStateFromStores()
+ @_ensureTimeout(@state)
_clearTimeout: =>
clearTimeout(@_timeout)
+ @_timeout = null
- _setNewTimeout: =>
- @_clearTimeout()
- @_timeout = setTimeout (=>
- @_hide()
- return
- ), 3000
+ _ensureTimeout: (state = @state) =>
+ if @_timeout
+ @_clearTimeout()
+ if state.show
+ @_timeout = setTimeout(@_hide, 3000)
_getStateFromStores: ->
tasks = UndoRedoStore.getMostRecent()
- show = false
- if tasks
- show = true
-
+ show = tasks?
return {show, tasks}
componentWillMount: ->
- @_unsubscribe = UndoRedoStore.listen(@_onChange)
+ @_unsubscribe = UndoRedoStore.listen =>
+ nextState = @_getStateFromStores()
+ @setState(nextState)
+ @_ensureTimeout(nextState)
componentWillUnmount: ->
@_clearTimeout()
@_unsubscribe()
render: =>
- inner = @_renderUndoRedoManager()
-
- names = classNames
+ classes = classNames
"undo-redo-manager": true