2 import flash.events.Event
4 import flash.utils.getQualifiedClassName
6 public class RegistryManager extends PollableBaseRegistry {
8 // This object will keep track of which registry last updated which
9 // values. This way there is no need to copy across values. We just check
10 // who had it last and ask her for it.
11 private var valueMap:Object;
12 private var registries:Array;
13 private var numRegistriesPolled:int;
14 private var pollRate:int;
16 public function RegistryManager(pollRate:int) {
19 this.numRegistriesPolled = 0;
20 this.pollRate = pollRate;
27 // INCEPTION INTENSIFIES
28 //this.addRegistry(super);
30 //setInterval(this.poll, this.pollRate);
33 public function addRegistry(registry:IPollableRegistry, registryCallback:Function = null) {
34 this.registries.push(registry);
35 registry.addEventListener(registry.getUpdateEventType(), this.updated);
36 registry.addEventListener(registry.getCycleCompleteEventType(), this.cycleComplete);
39 public override function get(propChain:String):* {
40 trace('should not see this');
41 return (this.valueMap[propChain] && this.valueMap[propChain].get(propChain));
44 public override function getLastUpdated():Array {
45 var updatedValues = [];
46 for (var propChain in this.valueMap) {
47 trace(this.valueMap[propChain].whoAmI());
49 // if we are looking at ourselves AND we have updated values, OR we are looking at something else and it has updated values
50 if(this.valueMap[propChain].getLastUpdated().indexOf(propChain) >= 0)
51 updatedValues.push(propChain)
57 private function poll() {
58 // This acts as a lock. After all the registries are polled, it resets to 0
59 // so we know it's safe to poll again.
60 if(this.numRegistriesPolled === 0) {
61 for each(var registry:Object in this.registries) {
62 this.numRegistriesPolled++;
63 var fn:Function = registry.getPollableFunction();
69 // Fires when _any_ of our registries are updated
70 private function updated(e:PollEvent) {
73 for each(var propChain in e.pollTarget.getLastUpdated()) {
74 this.valueMap[propChain] = e.pollTarget;
78 //for each(var propChain in e.pollTarget.getLastUpdated()) {
80 // this.valueMap[propChain] = e.pollTarget;
83 update && this.dispatchEvent(new PollEvent(this.getUpdateEventType(), this));
86 private function cycleComplete(e:PollEvent) {
87 if(this.numRegistriesPolled == this.registries.length) {
88 this.numRegistriesPolled = 0;
93 public override function whoAmI() {