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
This commit is contained in:
Leo Horie 2016-05-21 00:37:34 -04:00
parent db46bb4414
commit 0005cf26ee
13 changed files with 149 additions and 105 deletions

17
api/autoredraw.js Normal file
View file

@ -0,0 +1,17 @@
"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
}