Commiting to continue stuff at home
[swf-overlay.git] / PollableBaseRegistry.as
1 package {
2 import flash.events.Event;
3 import flash.events.EventDispatcher;
4
5 public class PollableBaseRegistry extends BaseRegistry implements IPollableRegistry {
6
7 private var dispatcher:EventDispatcher;
8 private var pollFunction:Function;
9
10 private static const REGISTRY_UPDATE = "registry_update";
11 private static const CYCLE_COMPLETE = "cycle_complete";
12
13 public function PollableBaseRegistry(pollFunction:Function = null) {
14 this.dispatcher = new EventDispatcher();
15 this.pollFunction = pollFunction || this.commit;
16 }
17
18 public function getPollableFunction():Function {
19 return this.pollFunction;
20 }
21
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);
26 this.stage = {};
27 this.dispatchUpdateEvent();
28 }
29
30 this.dispatchCycleCompleteEvent();
31 }
32
33 public function dispatchUpdateEvent():void {
34 this.dispatchEvent(new PollEvent(this.getUpdateEventType(), this));
35 }
36
37 public function getUpdateEventType():String {
38 return REGISTRY_UPDATE;
39 }
40
41 public function dispatchCycleCompleteEvent():void {
42 this.dispatchEvent(new PollEvent(this.getCycleCompleteEventType(), this));
43 }
44
45 public function getCycleCompleteEventType():String {
46 return CYCLE_COMPLETE;
47 }
48
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);
52 }
53 public function dispatchEvent(event:Event):Boolean {
54 return this.dispatcher.dispatchEvent(event);
55 }
56 public function hasEventListener(type:String):Boolean {
57 return this.dispatcher.hasEventListener(type);
58 }
59 public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
60 this.dispatcher.removeEventListener(type, listener, useCapture);
61 }
62 public function willTrigger(type:String):Boolean {
63 return this.dispatcher.willTrigger(type);
64 }
65
66 public function whoAmI() {
67 trace("poll base");
68 }
69
70 }
71
72 }