package { import flash.events.Event; import flash.events.EventDispatcher; public class PollableBaseRegistry extends BaseRegistry implements IPollableRegistry { private var dispatcher:EventDispatcher; private var pollFunction:Function; private static const REGISTRY_UPDATE = "registry_update"; private static const CYCLE_COMPLETE = "cycle_complete"; public function PollableBaseRegistry(pollFunction:Function = null) { this.dispatcher = new EventDispatcher(); this.pollFunction = pollFunction || this.commit; } public function getPollableFunction():Function { return this.pollFunction; } public override function commit():void { if(!Util.objectIsEmpty(this.stage)) { this.head = Util.extend(this.head, this.stage); this.lastUpdated = Util.toPropertyChains(this.stage); this.stage = {}; this.dispatchUpdateEvent(); } this.dispatchCycleCompleteEvent(); } public function dispatchUpdateEvent():void { this.dispatchEvent(new PollEvent(this.getUpdateEventType(), this)); } public function getUpdateEventType():String { return REGISTRY_UPDATE; } public function dispatchCycleCompleteEvent():void { this.dispatchEvent(new PollEvent(this.getCycleCompleteEventType(), this)); } public function getCycleCompleteEventType():String { return CYCLE_COMPLETE; } //Wrappers around EventDispatcher public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void { this.dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference); } public function dispatchEvent(event:Event):Boolean { return this.dispatcher.dispatchEvent(event); } public function hasEventListener(type:String):Boolean { return this.dispatcher.hasEventListener(type); } public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void { this.dispatcher.removeEventListener(type, listener, useCapture); } public function willTrigger(type:String):Boolean { return this.dispatcher.willTrigger(type); } public function whoAmI() { trace("poll base"); } } }