Last active
November 14, 2019 23:48
-
-
Save sarimarton/2d37cb3698900ac310d01af11aad8028 to your computer and use it in GitHub Desktop.
Auto-save
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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