/Frameworks/Foundation/objj.platform/CPNotificationCenter.j

http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 196 lines · 196 code · 0 blank · 0 comment · 0 complexity · d6d8b585c4b68b7f43348784e2baf41d MD5 · raw file

  1. i;9;CPArray.ji;14;CPDictionary.ji;16;CPNotification.ji;13;CPException.jc;6582;
  2. var _1=nil;
  3. var _2=objj_allocateClassPair(CPObject,"CPNotificationCenter"),_3=_2.isa;
  4. class_addIvars(_2,[new objj_ivar("_namedRegistries"),new objj_ivar("_unnamedRegistry")]);
  5. objj_registerClassPair(_2);
  6. objj_addClassForBundle(_2,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  7. class_addMethods(_2,[new objj_method(sel_getUid("init"),function(_4,_5){
  8. with(_4){
  9. _4=objj_msgSendSuper({receiver:_4,super_class:objj_getClass("CPObject")},"init");
  10. if(_4){
  11. _namedRegistries=objj_msgSend(CPDictionary,"dictionary");
  12. _unnamedRegistry=objj_msgSend(objj_msgSend(_CPNotificationRegistry,"alloc"),"init");
  13. }
  14. return _4;
  15. }
  16. }),new objj_method(sel_getUid("addObserver:selector:name:object:"),function(_6,_7,_8,_9,_a,_b){
  17. with(_6){
  18. var _c,_d=objj_msgSend(objj_msgSend(_CPNotificationObserver,"alloc"),"initWithObserver:selector:",_8,_9);
  19. if(_a==nil){
  20. _c=_unnamedRegistry;
  21. }else{
  22. if(!(_c=objj_msgSend(_namedRegistries,"objectForKey:",_a))){
  23. _c=objj_msgSend(objj_msgSend(_CPNotificationRegistry,"alloc"),"init");
  24. objj_msgSend(_namedRegistries,"setObject:forKey:",_c,_a);
  25. }
  26. }
  27. objj_msgSend(_c,"addObserver:object:",_d,_b);
  28. }
  29. }),new objj_method(sel_getUid("removeObserver:"),function(_e,_f,_10){
  30. with(_e){
  31. var _11=nil,_12=objj_msgSend(_namedRegistries,"keyEnumerator");
  32. while(_11=objj_msgSend(_12,"nextObject")){
  33. objj_msgSend(objj_msgSend(_namedRegistries,"objectForKey:",_11),"removeObserver:object:",_10,nil);
  34. }
  35. objj_msgSend(_unnamedRegistry,"removeObserver:object:",_10,nil);
  36. }
  37. }),new objj_method(sel_getUid("removeObserver:name:object:"),function(_13,_14,_15,_16,_17){
  38. with(_13){
  39. if(_16==nil){
  40. var _18=nil,_19=objj_msgSend(_namedRegistries,"keyEnumerator");
  41. while(_18=objj_msgSend(_19,"nextObject")){
  42. objj_msgSend(objj_msgSend(_namedRegistries,"objectForKey:",_18),"removeObserver:object:",_15,_17);
  43. }
  44. objj_msgSend(_unnamedRegistry,"removeObserver:object:",_15,_17);
  45. }else{
  46. objj_msgSend(objj_msgSend(_namedRegistries,"objectForKey:",_16),"removeObserver:object:",_15,_17);
  47. }
  48. }
  49. }),new objj_method(sel_getUid("postNotification:"),function(_1a,_1b,_1c){
  50. with(_1a){
  51. if(!_1c){
  52. objj_msgSend(CPException,"raise:reason:",CPInvalidArgumentException,"postNotification: does not except 'nil' notifications");
  53. }
  54. _1d(_1a,_1c);
  55. }
  56. }),new objj_method(sel_getUid("postNotificationName:object:userInfo:"),function(_1e,_1f,_20,_21,_22){
  57. with(_1e){
  58. _1d(_1e,objj_msgSend(objj_msgSend(CPNotification,"alloc"),"initWithName:object:userInfo:",_20,_21,_22));
  59. }
  60. }),new objj_method(sel_getUid("postNotificationName:object:"),function(_23,_24,_25,_26){
  61. with(_23){
  62. _1d(_23,objj_msgSend(objj_msgSend(CPNotification,"alloc"),"initWithName:object:userInfo:",_25,_26,nil));
  63. }
  64. })]);
  65. class_addMethods(_3,[new objj_method(sel_getUid("defaultCenter"),function(_27,_28){
  66. with(_27){
  67. if(!_1){
  68. _1=objj_msgSend(objj_msgSend(CPNotificationCenter,"alloc"),"init");
  69. }
  70. return _1;
  71. }
  72. })]);
  73. var _1d=function(_29,_2a){
  74. objj_msgSend(_29._unnamedRegistry,"postNotification:",_2a);
  75. objj_msgSend(objj_msgSend(_29._namedRegistries,"objectForKey:",objj_msgSend(_2a,"name")),"postNotification:",_2a);
  76. };
  77. var _2=objj_allocateClassPair(CPObject,"_CPNotificationRegistry"),_3=_2.isa;
  78. class_addIvars(_2,[new objj_ivar("_objectObservers"),new objj_ivar("_observerRemoval"),new objj_ivar("_postingObservers")]);
  79. objj_registerClassPair(_2);
  80. objj_addClassForBundle(_2,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  81. class_addMethods(_2,[new objj_method(sel_getUid("init"),function(_2b,_2c){
  82. with(_2b){
  83. if(_2b){
  84. _objectObservers=objj_msgSend(CPDictionary,"dictionary");
  85. }
  86. return _2b;
  87. }
  88. }),new objj_method(sel_getUid("addObserver:object:"),function(_2d,_2e,_2f,_30){
  89. with(_2d){
  90. if(!_30){
  91. _30=objj_msgSend(CPNull,"null");
  92. }
  93. var _31=objj_msgSend(_objectObservers,"objectForKey:",objj_msgSend(_30,"hash"));
  94. if(!_31){
  95. _31=[];
  96. objj_msgSend(_objectObservers,"setObject:forKey:",_31,objj_msgSend(_30,"hash"));
  97. }
  98. if(_31==_postingObservers){
  99. _postingObservers=objj_msgSend(_31,"copy");
  100. }
  101. _31.push(_2f);
  102. }
  103. }),new objj_method(sel_getUid("removeObserver:object:"),function(_32,_33,_34,_35){
  104. with(_32){
  105. var _36=[];
  106. if(_35==nil){
  107. var key=nil,_38=objj_msgSend(_objectObservers,"keyEnumerator");
  108. while(key=objj_msgSend(_38,"nextObject")){
  109. var _39=objj_msgSend(_objectObservers,"objectForKey:",key),_3a=_39?_39.length:0;
  110. while(_3a--){
  111. if(objj_msgSend(_39[_3a],"observer")==_34){
  112. _observerRemoval=YES;
  113. if(_39==_postingObservers){
  114. _postingObservers=objj_msgSend(_39,"copy");
  115. }
  116. _39.splice(_3a,1);
  117. }
  118. }
  119. if(!_39||_39.length==0){
  120. _36.push(key);
  121. }
  122. }
  123. }else{
  124. var key=objj_msgSend(_35,"hash"),_39=objj_msgSend(_objectObservers,"objectForKey:",key);
  125. _3a=_39?_39.length:0;
  126. while(_3a--){
  127. if(objj_msgSend(_39[_3a],"observer")==_34){
  128. _observerRemoval=YES;
  129. if(_39==_postingObservers){
  130. _postingObservers=objj_msgSend(_39,"copy");
  131. }
  132. _39.splice(_3a,1);
  133. }
  134. }
  135. if(!_39||_39.length==0){
  136. _36.push(key);
  137. }
  138. }
  139. var _3a=_36.length;
  140. while(_3a--){
  141. objj_msgSend(_objectObservers,"removeObjectForKey:",_36[_3a]);
  142. }
  143. }
  144. }),new objj_method(sel_getUid("postNotification:"),function(_3b,_3c,_3d){
  145. with(_3b){
  146. var _3e=objj_msgSend(_3d,"object");
  147. if(_3e!=nil&&(_postingObservers=objj_msgSend(_objectObservers,"objectForKey:",objj_msgSend(_3e,"hash")))){
  148. var _3f=_postingObservers,_40=_3f.length;
  149. _observerRemoval=NO;
  150. while(_40--){
  151. var _41=_postingObservers[_40];
  152. if(!_observerRemoval||objj_msgSend(_3f,"indexOfObjectIdenticalTo:",_41)!=CPNotFound){
  153. objj_msgSend(_41,"postNotification:",_3d);
  154. }
  155. }
  156. }
  157. _postingObservers=objj_msgSend(_objectObservers,"objectForKey:",objj_msgSend(objj_msgSend(CPNull,"null"),"hash"));
  158. if(!_postingObservers){
  159. return;
  160. }
  161. var _3f=_postingObservers,_40=_3f.length;
  162. _observerRemoval=NO;
  163. while(_40--){
  164. var _41=_postingObservers[_40];
  165. if(!_observerRemoval||objj_msgSend(_3f,"indexOfObjectIdenticalTo:",_41)!=CPNotFound){
  166. objj_msgSend(_41,"postNotification:",_3d);
  167. }
  168. }
  169. _postingObservers=nil;
  170. }
  171. }),new objj_method(sel_getUid("count"),function(_42,_43){
  172. with(_42){
  173. return objj_msgSend(_objectObservers,"count");
  174. }
  175. })]);
  176. var _2=objj_allocateClassPair(CPObject,"_CPNotificationObserver"),_3=_2.isa;
  177. class_addIvars(_2,[new objj_ivar("_observer"),new objj_ivar("_selector")]);
  178. objj_registerClassPair(_2);
  179. objj_addClassForBundle(_2,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  180. class_addMethods(_2,[new objj_method(sel_getUid("initWithObserver:selector:"),function(_44,_45,_46,_47){
  181. with(_44){
  182. if(_44){
  183. _observer=_46;
  184. _selector=_47;
  185. }
  186. return _44;
  187. }
  188. }),new objj_method(sel_getUid("observer"),function(_48,_49){
  189. with(_48){
  190. return _observer;
  191. }
  192. }),new objj_method(sel_getUid("postNotification:"),function(_4a,_4b,_4c){
  193. with(_4a){
  194. objj_msgSend(_observer,"performSelector:withObject:",_selector,_4c);
  195. }
  196. })]);