Skip to content

Commit b454e9a

Browse files
kfuledead-claudia
authored andcommitted
Allow additional async redraw even if the first redraw is skipped
1 parent 043a714 commit b454e9a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

render/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,8 @@ module.exports = function() {
811811
if (typeof handler === "function") result = handler.call(ev.currentTarget, ev)
812812
else if (typeof handler.handleEvent === "function") handler.handleEvent(ev)
813813
var eventRedraw = this._
814-
if (eventRedraw && ev.redraw !== false) {
815-
eventRedraw()
814+
if (eventRedraw) {
815+
if (ev.redraw !== false) eventRedraw()
816816
if (result != null && typeof result.then === "function") {
817817
Promise.resolve(result).then(function () {
818818
if (ev.redraw !== false) eventRedraw()

render/tests/test-event.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,38 @@ o.spec("event", function() {
848848
})
849849
})
850850
})
851+
o("async function (event.redraw = false, await Promise, event.redraw = true)", function(done) {
852+
var thenCB
853+
var div = m("div", {onclick: async function (ev) {
854+
// set event.redraw = false to prevent sync redraw
855+
ev.redraw = false
856+
await new Promise(function(resolve){thenCB = resolve})
857+
// set event.redraw = true to enable async redraw
858+
ev.redraw = true
859+
}})
860+
var e = $window.document.createEvent("MouseEvents")
861+
e.initEvent("click", true, true)
862+
863+
render(root, div)
864+
div.dom.dispatchEvent(e)
865+
866+
o(redraw.callCount).equals(0)
867+
868+
callAsync(function() {
869+
// not resolved yet
870+
o(redraw.callCount).equals(0)
871+
872+
// resolve
873+
thenCB()
874+
callAsync(function() {
875+
o(redraw.callCount).equals(1)
876+
o(redraw.this).equals(undefined)
877+
o(redraw.args.length).equals(0)
878+
879+
done()
880+
})
881+
})
882+
})
851883
o("async function (multiple await)", function(done) {
852884
var thenCB1, thenCB2
853885
var div = m("div", {onclick: async function () {

0 commit comments

Comments
 (0)