Skip to content

Commit 5931f69

Browse files
authored
limit the state updates to a maximum updateRate
Van still provides the tools to limit the update rate. ```JS let {updateRate} = van updateRate(100) ``` This set´s the update rate to 100ms. state changes are delayed by up to 100 ms, before they are propagated to the DOM. If multiple changes are applied withi this time, only the last is updating the DOM.
1 parent d6658be commit 5931f69

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/van.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function end(cnt = 1) {
1818
}
1919

2020
// This file consistently uses `let` keyword instead of `const` for reducing the bundle size.
21+
var updateRate = 0 // Initial update timeout 0 ms
2122

2223
// Aliasing some builtin symbols to reduce the bundle size.
2324
let Obj = Object, _undefined, protoOf = Object.getPrototypeOf
@@ -35,7 +36,7 @@ let stateProto = {
3536
let s = this, curV = s._val
3637
if (v !== curV) {
3738
if (s.oldVal === curV)
38-
changedStates = addAndScheduleOnFirst(changedStates, s, updateDoms)
39+
changedStates = addAndScheduleOnFirst(changedStates, s, updateDoms, updateRate)
3940
else if (v === s.oldVal)
4041
changedStates.delete(s)
4142
s._val = v
@@ -110,5 +111,5 @@ let bind = (...deps) => {
110111
}
111112
return binding.dom
112113
}
113-
114-
export default {add, tags, state, bind, begin, end}
114+
let updateRate = (t) => updateRate = t
115+
export default {add, tags, state, bind, begin, end, updateRate}

0 commit comments

Comments
 (0)