-
Notifications
You must be signed in to change notification settings - Fork 4
/
redraw.js
41 lines (35 loc) · 1.12 KB
/
redraw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Use this when you want to use `m.redraw` to link from streams or other
* synchronously-updating cells.
*
* Note: call `redraw.ready` in `oncreate` to unlock it.
*
* Also, you may call `redraw.lock` in `onbeforeupdate` and `redraw.ready` in
* `onupdate`, to avoid unnecessary rendering calls.
*/
;(function () {
"use strict"
// Ideally, this would use a hook to know when Mithril starts/finishes
// redrawing.
var p = Promise.resolve()
var mithril
if (typeof module === "object" && module && module.exports) {
module.exports = makeRedraw
mithril = require("mithril")
} else if (typeof m !== "function") {
throw new Error("Mithril must be loaded first!")
} else {
(m.helpers || (m.helpers = {})).makeRedraw = makeRedraw
mithril = m
}
function makeRedraw(state) {
var ready = false
var redraw = state != null
? function () { if (ready) state.redraw() }
: function () { if (ready) p.then(mithril.redraw) }
redraw.ready = function () {
ready = true
}
return redraw
}
})()