peterS.: [EventDispatcher] -besser nachvollziehbarer letzter beispielcode

Beitrag lesen

ein letztes "hallo" in die runde fuer alle Geduldigen und Interessierten,

[spam]: der zuletzt gepostete beispiel-code kommt hier nochmal
mit *debug*-ausgabe, um das grundlegende zusammenspiel der
komponenten besser nachvollziehbar zu machen ...

... bitte mit *copy and paste* auf die [jconsole] loslassen:

(function () {  
  
  
//[http://dean.edwards.name/packer/]  -  shrinked + encoded  -  2144 bytes  :  
  eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4 1c=(2(){4 g=16.12.k,u=(2(a){3((a&&a.k&&a.k())||"")}),11=(2(){4 b=(/^\\[t\\s+Z\\]$/);3(2(a){3 b.O(g.w(a))})})(),B=(2(){4 b=(/^\\[t\\s+13\\]$/);3(2(a){3 b.O(g.w(a))})})(),C=(2(a){3((8 a=="2")&&(8 a.w=="2")&&(8 a.10=="2"))}),I={A:(2(a,b){4 c=(a.M-1);W(c>-1){5(a[c]===b){17}--c}3 c})},G=(2(a,b){6.L=G;6.o=a;6.9=b;6.m=x Y()}),v=(2(b,c,d){6.L=v;4 e=x G(b,c);6.X=(2(a){5((8 a=="t")&&a){a.o=e.o;a.9=e.9;a.m=e.m}H{a={o:e.o,9:e.9,m:e.m}}d(a)});6.Q=(2(){3 c});6.q=(2(){3 d})}),K=(2(){4 f={},i=(2(a,b){4 c=f[a],D=J;5(c){4 d=c.F,h=c.h,7=I.A(d,b);5(7>=0){d.V(7,1);h.V(7,1);D=N}}3 D});6.p=(2(a,b){4 c;5(a&&B(a)&&C(b)){4 d=f[a],j=x v(6,a,b);5(d){4 e=d.F,h=d.h,7=I.A(e,b);5(7==-1){e.U(j.q());h.U(j);c=j}H{c=h[7]}}H{d=f[a]={};d.F=[j.q()];d.h=[j];c=j}}3 c});6.i=(2(a,b){3((B(a)&&C(b)&&i(a,b))||((a 15 v)&&i(a.Q(),a.q()))||J)});6.l=(2(a){4 b=J,9=(((8 a=="t")&&(8 a.9=="T")&&a.9)||((8 a=="T")&&a)),y=(9&&f[9]);5(y){4 c=(y&&y.h),E=((c&&c.M)||0),7=0;5(E>=1){W(7<E){c[7++].X(a)}b=N}}3 b})}),n=x K,r={S:n.p.k(),P:n.i.k(),R:n.l.k()};z n;3{14:(2(a){5((8 a.p=="2")||a.18||(8 a.i=="2")||a.19||(8 a.l=="2")||a.1a){3}K.w(a)}),1b:(2(a){5(u(a.p)===r.S){z a.p}5(u(a.i)===r.P){z a.i}5(u(a.l)===r.R){z a.l}})}})();',62,75,'||function|return|var|if|this|idx|typeof|type||||||||listeners|removeEventListener|listener|toString|dispatchEvent|timeStamp|pseudoTarget|target|addEventListener|getHandler|CROSSCHECK_TARGET||object|stringify|EventListener|call|new|event|delete|indexOf|isString|isFunction|successfully|len|handlers|Event|else|Handler|false|EventTarget|constructor|length|true|test|removeListenerString|getType|dispatchEventString|addListenerString|string|push|splice|while|handleEvent|Date|Boolean|apply|isBoolean|prototype|String|register|instanceof|Object|break|attachEvent|detachEvent|fireEvent|unsubscribe|EventDispatcher'.split('|'),0,{}));  
  
  
  
  var Processor = (function () {  
  
  
    var xyz, abc, objStatistics, objAnotherStatistics,  
  
    computeStatistics = (function () {/*  
  
      ... */  
      print("Processor - private function [computeStatistics] - dispatching \"onStatisticsComputed\"");  
  
      Processor.dispatchEvent({type: "onStatisticsComputed", result: objStatistics/*, even more key:value pairs */});  
    }),  
    computeAnotherStatistics = (function () {/*  
  
      ... */  
      print("Processor - private function [computeAnotherStatistics] - dispatching \"onAnotherStatisticsComputed\"");  
  
      Processor.dispatchEvent({type: "onAnotherStatisticsComputed", result: objAnotherStatistics/*, even more key:value pairs */});  
    });  
  
  
    return {  
  
      initialize : (function (arg01, arg02/*, ...*/) {  
  
        xyz = arg01;  
        abc = arg02;  
      }),  
      getStatistics : (function () {  
  
        computeStatistics();  
      }),  
      getAnotherStatistics : (function () {  
  
        computeAnotherStatistics();  
      })  
    };  
  })();  
  
  
  EventDispatcher.register(Processor); // applying signal slot konzept onto [Processor] and all elements that will listen to its events.  
  
  
  
  var ResultsController = (function () {  
  
  
    var processor,  
  
    displayStatistics = (function (evt) {/*  
  
      ... */  
      print("ResultsController - private function [displayStatistics] is handler for event \"onStatisticsComputed\" which it is listening for");  
    }),  
    displayAnotherStatistics = (function (evt) {/*  
  
      ... */  
      print("ResultsController - private function [displayAnotherStatistics] is handler for event \"onAnotherStatisticsComputed\" which it is listening for");  
    });  
  
  
    return {  
  
      initialize : (function (arg01/*, ...*/) {  
  
        processor = arg01;  
  
        processor.addEventListener("onStatisticsComputed", displayStatistics);  
        processor.addEventListener("onAnotherStatisticsComputed", displayAnotherStatistics);  
      })  
    };  
  })();  
  
  
  
  var Requestor = (function () {  
  
    var processor;  
  
    return {  
  
      initialize : (function (arg01/*, ...*/) {  
  
        processor = arg01;  
  
        processor.getStatistics();  
        processor.getAnotherStatistics();  
      })  
    };  
  })();  
  
  
  
  Processor.initialize("val01", "val02"/*, ...*/);  
  
  ResultsController.initialize(Processor);  
  Requestor.initialize(Processor);  
  
})();

viel spass - peterS. - pseliger@gmx.net

--
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]