2 import flash.events.Event;
3 import flash.events.EventDispatcher;
5 public class PollableBaseRegistry extends BaseRegistry implements IPollableRegistry {
7 private var dispatcher:EventDispatcher;
8 private var pollFunction:Function;
10 private static const REGISTRY_UPDATE = "registry_update";
11 private static const CYCLE_COMPLETE = "cycle_complete";
13 public function PollableBaseRegistry(pollFunction:Function = null) {
14 this.dispatcher = new EventDispatcher();
15 this.pollFunction = pollFunction || this.commit;
18 public function getPollableFunction():Function {
19 return this.pollFunction;
22 public override function commit():void {
23 if(!Util.objectIsEmpty(this.stage)) {
24 this.head = Util.extend(this.head, this.stage);
25 this.lastUpdated = Util.toPropertyChains(this.stage);
27 this.dispatchUpdateEvent();
30 this.dispatchCycleCompleteEvent();
33 public function dispatchUpdateEvent():void {
34 this.dispatchEvent(new PollEvent(this.getUpdateEventType(), this));
37 public function getUpdateEventType():String {
38 return REGISTRY_UPDATE;
41 public function dispatchCycleCompleteEvent():void {
42 this.dispatchEvent(new PollEvent(this.getCycleCompleteEventType(), this));
45 public function getCycleCompleteEventType():String {
46 return CYCLE_COMPLETE;
49 //Wrappers around EventDispatcher
50 public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void {
51 this.dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
53 public function dispatchEvent(event:Event):Boolean {
54 return this.dispatcher.dispatchEvent(event);
56 public function hasEventListener(type:String):Boolean {
57 return this.dispatcher.hasEventListener(type);
59 public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
60 this.dispatcher.removeEventListener(type, listener, useCapture);
62 public function willTrigger(type:String):Boolean {
63 return this.dispatcher.willTrigger(type);
66 public function whoAmI() {