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:
parent
db46bb4414
commit
0005cf26ee
13 changed files with 149 additions and 105 deletions
17
api/autoredraw.js
Normal file
17
api/autoredraw.js
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue