Skip to content

Instantly share code, notes, and snippets.

@sarimarton
Last active November 14, 2019 23:48
Show Gist options
  • Save sarimarton/2d37cb3698900ac310d01af11aad8028 to your computer and use it in GitHub Desktop.
Save sarimarton/2d37cb3698900ac310d01af11aad8028 to your computer and use it in GitHub Desktop.
Auto-save
Auto-save
Idle*
change -> Saving
Saving
response -> Idle
change -> Debounce Pending
Debounce Pending
change -> Debounce Pending
timeout -> Pending
response -> Debouncing
Pending
response -> Saving
change -> Debounce Pending
Debouncing
timeout -> Saving
change -> Debouncing
let debounceId
let revId = 0
function render(model){
let activeState = model.active_states[0].name
if (activeState === 'Saving') {
revId += 1
setTimeout((id => () => id === revId && model.emit('response'))(revId), 3000)
}
if (activeState === 'Debouncing' || activeState === 'Debounce Pending') {
clearTimeout(debounceId)
debounceId = setTimeout(() => model.emit('timeout'), 500)
}
return (<>
Rev: {revId}<br />{activeState}<br />
<textArea onChange={() => model.emit('change')}></textArea>
</>)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment