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

53
api/tests/test-pubsub.js Normal file
View file

@ -0,0 +1,53 @@
"use strict"
var o = require("../../ospec/ospec")
var apiPubSub = require("../../api/pubsub")
o.spec("pubsub", function() {
var pubsub
o.beforeEach(function() {
pubsub = apiPubSub()
})
o("it shouldn't error if there are no renderers", function() {
pubsub.publish()
})
o("it should run a single renderer entry", function() {
var spy = o.spy()
pubsub.subscribe(spy)
pubsub.publish()
o(spy.callCount).equals(1)
pubsub.publish()
pubsub.publish()
pubsub.publish()
o(spy.callCount).equals(4)
})
o("it should run all renderer entries", function() {
var spy1 = o.spy()
var spy2 = o.spy()
var spy3 = o.spy()
pubsub.subscribe(spy1)
pubsub.subscribe(spy2)
pubsub.subscribe(spy3)
pubsub.publish()
o(spy1.callCount).equals(1)
o(spy2.callCount).equals(1)
o(spy3.callCount).equals(1)
pubsub.publish()
o(spy1.callCount).equals(2)
o(spy2.callCount).equals(2)
o(spy3.callCount).equals(2)
})
})