<script>
import { debounce } from 'lodash-es'
let index = 0
let activities = []
let pending = []
function click() {
pending = [...pending, {text: `Activity #${++index}`}]
debouncedCommit()
}
function commit() {
if (pending.length == 0) return
if (pending.length == 1) {
activities = [...activities, pending[0]]
} else {
activities = [...activities, pending]
}
pending = []
}
let debouncedCommit = debounce(commit, 500)
</script>
<h1>Rollup with Debounce</h1>
<p>When multiple activities are added quickly, debounce is used to roll them up into a set.</p>
<button on:click={click}>
Add activity
</button>
<h2>Activities</h2>