mithril-vndb/api/autoredraw.js
Leo Horie 0005cf26ee refactor redraw into pubsub and autoredraw
- pubsub is a basic pubsub impl
- autoredraw is glue code to register callback to pubsub and onevent

moved e.redraw to autoredraw
2016-05-21 00:37:34 -04:00

17 lines
No EOL
358 B
JavaScript

"use strict"
var throttle = require("../api/throttle")
module.exports = function(root, renderer, pubsub, callback) {
var run = throttle(callback)
renderer.setEventCallback(function(e) {
if (e.redraw !== false) run()
})
if (pubsub != null) {
if (root.redraw) pubsub.unsubscribe(root.redraw)
pubsub.subscribe(run)
}
return root.redraw = run
}