PageRenderTime 29ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/Frameworks/Foundation/objj.platform/CPKeyValueObserving.j

http://github.com/polymar/polish
Unknown | 377 lines | 377 code | 0 blank | 0 comment | 0 complexity | cdba3175431d4a35cdc33af85d7951c6 MD5 | raw file
  1i;9;CPArray.ji;14;CPDictionary.ji;13;CPException.ji;10;CPObject.ji;7;CPSet.jc;14900;
  2var _1=objj_getClass("CPObject");
  3if(!_1){
  4objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPObject\""));
  5}
  6var _2=_1.isa;
  7class_addMethods(_1,[new objj_method(sel_getUid("willChangeValueForKey:"),function(_3,_4,_5){
  8with(_3){
  9}
 10}),new objj_method(sel_getUid("didChangeValueForKey:"),function(_6,_7,_8){
 11with(_6){
 12}
 13}),new objj_method(sel_getUid("willChange:valuesAtIndexes:forKey:"),function(_9,_a,_b,_c,_d){
 14with(_9){
 15}
 16}),new objj_method(sel_getUid("didChange:valuesAtIndexes:forKey:"),function(_e,_f,_10,_11,key){
 17with(_e){
 18}
 19}),new objj_method(sel_getUid("addObserver:forKeyPath:options:context:"),function(_13,_14,_15,_16,_17,_18){
 20with(_13){
 21if(!_15||!_16){
 22return;
 23}
 24objj_msgSend(objj_msgSend(_CPKVOProxy,"proxyForObject:",_13),"_addObserver:forKeyPath:options:context:",_15,_16,_17,_18);
 25}
 26}),new objj_method(sel_getUid("removeObserver:forKeyPath:"),function(_19,_1a,_1b,_1c){
 27with(_19){
 28if(!_1b||!_1c){
 29return;
 30}
 31objj_msgSend(objj_msgSend(_1d,"objectForKey:",objj_msgSend(_19,"hash")),"_removeObserver:forKeyPath:",_1b,_1c);
 32}
 33})]);
 34class_addMethods(_2,[new objj_method(sel_getUid("automaticallyNotifiesObserversForKey:"),function(_1e,_1f,_20){
 35with(_1e){
 36return YES;
 37}
 38}),new objj_method(sel_getUid("keyPathsForValuesAffectingValueForKey:"),function(_21,_22,_23){
 39with(_21){
 40var _24=_23.charAt(0).toUpperCase()+_23.substring(1);
 41selector="keyPathsForValuesAffectingValueFor"+_24;
 42if(objj_msgSend(objj_msgSend(_21,"class"),"respondsToSelector:",selector)){
 43return objj_msgSend(objj_msgSend(_21,"class"),selector);
 44}
 45return objj_msgSend(CPSet,"set");
 46}
 47})]);
 48CPKeyValueObservingOptionNew=1<<0;
 49CPKeyValueObservingOptionOld=1<<1;
 50CPKeyValueObservingOptionInitial=1<<2;
 51CPKeyValueObservingOptionPrior=1<<3;
 52CPKeyValueChangeKindKey="CPKeyValueChangeKindKey";
 53CPKeyValueChangeNewKey="CPKeyValueChangeNewKey";
 54CPKeyValueChangeOldKey="CPKeyValueChangeOldKey";
 55CPKeyValueChangeIndexesKey="CPKeyValueChangeIndexesKey";
 56CPKeyValueChangeNotificationIsPriorKey="CPKeyValueChangeNotificationIsPriorKey";
 57CPKeyValueChangeSetting=1;
 58CPKeyValueChangeInsertion=2;
 59CPKeyValueChangeRemoval=3;
 60CPKeyValueChangeReplacement=4;
 61var _25=CPKeyValueObservingOptionNew|CPKeyValueObservingOptionOld;
 62var _1d=objj_msgSend(CPDictionary,"dictionary"),_26=objj_msgSend(CPDictionary,"dictionary");
 63var _1=objj_allocateClassPair(CPObject,"_CPKVOProxy"),_2=_1.isa;
 64class_addIvars(_1,[new objj_ivar("_targetObject"),new objj_ivar("_nativeClass"),new objj_ivar("_changesForKey"),new objj_ivar("_observersForKey"),new objj_ivar("_replacedKeys")]);
 65objj_registerClassPair(_1);
 66objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 67class_addMethods(_1,[new objj_method(sel_getUid("initWithTarget:"),function(_27,_28,_29){
 68with(_27){
 69_27=objj_msgSendSuper({receiver:_27,super_class:objj_getClass("CPObject")},"init");
 70_targetObject=_29;
 71_nativeClass=objj_msgSend(_29,"class");
 72_observersForKey=objj_msgSend(CPDictionary,"dictionary");
 73_changesForKey=objj_msgSend(CPDictionary,"dictionary");
 74_replacedKeys=objj_msgSend(CPSet,"set");
 75return _27;
 76}
 77}),new objj_method(sel_getUid("_replaceClass"),function(_2a,_2b){
 78with(_2a){
 79var _2c=_nativeClass,_2d="$KVO_"+class_getName(_nativeClass),_2e=objj_lookUpClass(_2d);
 80if(_2e){
 81_targetObject.isa=_2e;
 82return;
 83}
 84var _2f=objj_allocateClassPair(_2c,_2d);
 85objj_registerClassPair(_2f);
 86_class_initialize(_2f);
 87var _30=_CPKVOModelSubclass.method_list,_31=_30.length;
 88for(var i=0;i<_31;i++){
 89var _33=_30[i];
 90class_addMethod(_2f,method_getName(_33),method_getImplementation(_33),"");
 91}
 92_targetObject.isa=_2f;
 93}
 94}),new objj_method(sel_getUid("_replaceSetterForKey:"),function(_34,_35,_36){
 95with(_34){
 96if(objj_msgSend(_replacedKeys,"containsObject:",_36)||!objj_msgSend(_nativeClass,"automaticallyNotifiesObserversForKey:",_36)){
 97return;
 98}
 99var _37=_nativeClass,_38=_36.charAt(0).toUpperCase()+_36.substring(1),_39=false,_3a=["set"+_38+":",_3b,"_set"+_38+":",_3b,"insertObject:in"+_38+"AtIndex:",_3c,"replaceObjectIn"+_38+"AtIndex:withObject:",_3d,"removeObjectFrom"+_38+"AtIndex:",_3e];
100for(var i=0,_40=_3a.length;i<_40;i+=2){
101var _41=sel_getName(_3a[i]),_42=_3a[i+1];
102if(objj_msgSend(_nativeClass,"instancesRespondToSelector:",_41)){
103var _43=class_getInstanceMethod(_nativeClass,_41);
104class_addMethod(_targetObject.isa,_41,_42(_36,_43),"");
105_39=true;
106}
107}
108if(_39){
109return;
110}
111var _44=objj_msgSend(objj_msgSend(_nativeClass,"keyPathsForValuesAffectingValueForKey:",_36),"allObjects");
112if(!_44){
113return;
114}
115var _45=objj_msgSend(_26,"objectForKey:",objj_msgSend(_nativeClass,"hash"));
116if(!_45){
117_45=objj_msgSend(CPDictionary,"new");
118objj_msgSend(_26,"setObject:forKey:",_45,objj_msgSend(_nativeClass,"hash"));
119}
120for(var i=0,_40=_44.length;i<_40;i++){
121var _46=_44[i],_47=objj_msgSend(_45,"objectForKey:",_46);
122if(!_47){
123_47=objj_msgSend(CPSet,"new");
124objj_msgSend(_45,"setObject:forKey:",_47,_46);
125}
126objj_msgSend(_47,"addObject:",_36);
127objj_msgSend(_34,"_replaceSetterForKey:",_46);
128}
129}
130}),new objj_method(sel_getUid("_addObserver:forKeyPath:options:context:"),function(_48,_49,_4a,_4b,_4c,_4d){
131with(_48){
132if(!_4a){
133return;
134}
135var _4e=nil;
136if(_4b.indexOf(".")!=CPNotFound){
137_4e=objj_msgSend(objj_msgSend(_CPKVOForwardingObserver,"alloc"),"initWithKeyPath:object:observer:options:context:",_4b,_targetObject,_4a,_4c,_4d);
138}else{
139objj_msgSend(_48,"_replaceSetterForKey:",_4b);
140}
141var _4f=objj_msgSend(_observersForKey,"objectForKey:",_4b);
142if(!_4f){
143_4f=objj_msgSend(CPDictionary,"dictionary");
144objj_msgSend(_observersForKey,"setObject:forKey:",_4f,_4b);
145}
146objj_msgSend(_4f,"setObject:forKey:",_50(_4a,_4c,_4d,_4e),objj_msgSend(_4a,"hash"));
147if(_4c&CPKeyValueObservingOptionInitial){
148var _51=objj_msgSend(_targetObject,"valueForKeyPath:",_4b);
149if(_51===nil||_51===undefined){
150_51=objj_msgSend(CPNull,"null");
151}
152var _52=objj_msgSend(CPDictionary,"dictionaryWithObject:forKey:",_51,CPKeyValueChangeNewKey);
153objj_msgSend(_4a,"observeValueForKeyPath:ofObject:change:context:",_4b,_48,_52,_4d);
154}
155}
156}),new objj_method(sel_getUid("_removeObserver:forKeyPath:"),function(_53,_54,_55,_56){
157with(_53){
158var _57=objj_msgSend(_observersForKey,"objectForKey:",_56);
159if(_56.indexOf(".")!=CPNotFound){
160var _58=objj_msgSend(_57,"objectForKey:",objj_msgSend(_55,"hash")).forwarder;
161objj_msgSend(_58,"finalize");
162}
163objj_msgSend(_57,"removeObjectForKey:",objj_msgSend(_55,"hash"));
164if(!objj_msgSend(_57,"count")){
165objj_msgSend(_observersForKey,"removeObjectForKey:",_56);
166}
167if(!objj_msgSend(_observersForKey,"count")){
168_targetObject.isa=_nativeClass;
169objj_msgSend(_1d,"removeObjectForKey:",objj_msgSend(_targetObject,"hash"));
170}
171}
172}),new objj_method(sel_getUid("_sendNotificationsForKey:changeOptions:isBefore:"),function(_59,_5a,_5b,_5c,_5d){
173with(_59){
174var _5e=objj_msgSend(_changesForKey,"objectForKey:",_5b);
175if(_5d){
176_5e=_5c;
177var _5f=objj_msgSend(_5e,"objectForKey:",CPKeyValueChangeIndexesKey);
178if(_5f){
179var _60=objj_msgSend(_5e,"objectForKey:",CPKeyValueChangeKindKey);
180if(_60==CPKeyValueChangeReplacement||_60==CPKeyValueChangeRemoval){
181var _61=objj_msgSend(objj_msgSend(_targetObject,"mutableArrayValueForKeyPath:",_5b),"objectsAtIndexes:",_5f);
182objj_msgSend(_5e,"setValue:forKey:",_61,CPKeyValueChangeOldKey);
183}
184}else{
185var _62=objj_msgSend(_targetObject,"valueForKey:",_5b);
186if(_62===nil||_62===undefined){
187_62=objj_msgSend(CPNull,"null");
188}
189objj_msgSend(_5e,"setObject:forKey:",_62,CPKeyValueChangeOldKey);
190}
191objj_msgSend(_5e,"setObject:forKey:",1,CPKeyValueChangeNotificationIsPriorKey);
192objj_msgSend(_changesForKey,"setObject:forKey:",_5e,_5b);
193}else{
194objj_msgSend(_5e,"removeObjectForKey:",CPKeyValueChangeNotificationIsPriorKey);
195var _5f=objj_msgSend(_5e,"objectForKey:",CPKeyValueChangeIndexesKey);
196if(_5f){
197var _60=objj_msgSend(_5e,"objectForKey:",CPKeyValueChangeKindKey);
198if(_60==CPKeyValueChangeReplacement||_60==CPKeyValueChangeInsertion){
199var _61=objj_msgSend(objj_msgSend(_targetObject,"mutableArrayValueForKeyPath:",_5b),"objectsAtIndexes:",_5f);
200objj_msgSend(_5e,"setValue:forKey:",_61,CPKeyValueChangeNewKey);
201}
202}else{
203var _63=objj_msgSend(_targetObject,"valueForKey:",_5b);
204if(_63===nil||_63===undefined){
205_63=objj_msgSend(CPNull,"null");
206}
207objj_msgSend(_5e,"setObject:forKey:",_63,CPKeyValueChangeNewKey);
208}
209}
210var _64=objj_msgSend(objj_msgSend(_observersForKey,"objectForKey:",_5b),"allValues"),_65=objj_msgSend(_64,"count");
211while(_65--){
212var _66=_64[_65];
213if(_5d&&(_66.options&CPKeyValueObservingOptionPrior)){
214objj_msgSend(_66.observer,"observeValueForKeyPath:ofObject:change:context:",_5b,_targetObject,_5e,_66.context);
215}else{
216if(!_5d){
217objj_msgSend(_66.observer,"observeValueForKeyPath:ofObject:change:context:",_5b,_targetObject,_5e,_66.context);
218}
219}
220}
221var _67=objj_msgSend(objj_msgSend(objj_msgSend(_26,"objectForKey:",objj_msgSend(_nativeClass,"hash")),"objectForKey:",_5b),"allObjects");
222if(!_67){
223return;
224}
225for(var i=0,_65=_67.length;i<_65;i++){
226objj_msgSend(_59,"_sendNotificationsForKey:changeOptions:isBefore:",_67[i],_5c,_5d);
227}
228}
229})]);
230class_addMethods(_2,[new objj_method(sel_getUid("proxyForObject:"),function(_69,_6a,_6b){
231with(_69){
232var _6c=objj_msgSend(_1d,"objectForKey:",objj_msgSend(_6b,"hash"));
233if(_6c){
234return _6c;
235}
236_6c=objj_msgSend(objj_msgSend(_69,"alloc"),"initWithTarget:",_6b);
237objj_msgSend(_6c,"_replaceClass");
238objj_msgSend(_1d,"setObject:forKey:",_6c,objj_msgSend(_6b,"hash"));
239return _6c;
240}
241})]);
242var _1=objj_allocateClassPair(Nil,"_CPKVOModelSubclass"),_2=_1.isa;
243objj_registerClassPair(_1);
244objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
245class_addMethods(_1,[new objj_method(sel_getUid("willChangeValueForKey:"),function(_6d,_6e,_6f){
246with(_6d){
247if(!_6f){
248return;
249}
250var _70=objj_msgSend(CPDictionary,"dictionaryWithObject:forKey:",CPKeyValueChangeSetting,CPKeyValueChangeKindKey);
251objj_msgSend(objj_msgSend(_CPKVOProxy,"proxyForObject:",_6d),"_sendNotificationsForKey:changeOptions:isBefore:",_6f,_70,YES);
252}
253}),new objj_method(sel_getUid("didChangeValueForKey:"),function(_71,_72,_73){
254with(_71){
255if(!_73){
256return;
257}
258objj_msgSend(objj_msgSend(_CPKVOProxy,"proxyForObject:",_71),"_sendNotificationsForKey:changeOptions:isBefore:",_73,nil,NO);
259}
260}),new objj_method(sel_getUid("willChange:valuesAtIndexes:forKey:"),function(_74,_75,_76,_77,_78){
261with(_74){
262if(!_78){
263return;
264}
265var _79=objj_msgSend(CPDictionary,"dictionaryWithObjects:forKeys:",[_76,_77],[CPKeyValueChangeKindKey,CPKeyValueChangeIndexesKey]);
266objj_msgSend(objj_msgSend(_CPKVOProxy,"proxyForObject:",_74),"_sendNotificationsForKey:changeOptions:isBefore:",_78,_79,YES);
267}
268}),new objj_method(sel_getUid("didChange:valuesAtIndexes:forKey:"),function(_7a,_7b,_7c,_7d,_7e){
269with(_7a){
270if(!_7e){
271return;
272}
273objj_msgSend(objj_msgSend(_CPKVOProxy,"proxyForObject:",_7a),"_sendNotificationsForKey:changeOptions:isBefore:",_7e,nil,NO);
274}
275}),new objj_method(sel_getUid("class"),function(_7f,_80){
276with(_7f){
277return objj_msgSend(_1d,"objectForKey:",objj_msgSend(_7f,"hash"))._nativeClass;
278}
279}),new objj_method(sel_getUid("superclass"),function(_81,_82){
280with(_81){
281return objj_msgSend(objj_msgSend(_81,"class"),"superclass");
282}
283}),new objj_method(sel_getUid("isKindOfClass:"),function(_83,_84,_85){
284with(_83){
285return objj_msgSend(objj_msgSend(_83,"class"),"isSubclassOfClass:",_85);
286}
287}),new objj_method(sel_getUid("isMemberOfClass:"),function(_86,_87,_88){
288with(_86){
289return objj_msgSend(_86,"class")==_88;
290}
291}),new objj_method(sel_getUid("className"),function(_89,_8a){
292with(_89){
293return objj_msgSend(_89,"class").name;
294}
295})]);
296var _1=objj_allocateClassPair(CPObject,"_CPKVOForwardingObserver"),_2=_1.isa;
297class_addIvars(_1,[new objj_ivar("_object"),new objj_ivar("_observer"),new objj_ivar("_context"),new objj_ivar("_firstPart"),new objj_ivar("_secondPart"),new objj_ivar("_value")]);
298objj_registerClassPair(_1);
299objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
300class_addMethods(_1,[new objj_method(sel_getUid("initWithKeyPath:object:observer:options:context:"),function(_8b,_8c,_8d,_8e,_8f,_90,_91){
301with(_8b){
302_8b=objj_msgSendSuper({receiver:_8b,super_class:objj_getClass("CPObject")},"init");
303_context=_91;
304_observer=_8f;
305_object=_8e;
306var _92=_8d.indexOf(".");
307if(_92==CPNotFound){
308objj_msgSend(CPException,"raise:reason:",CPInvalidArgumentException,"Created _CPKVOForwardingObserver without compound key path: "+_8d);
309}
310_firstPart=_8d.substring(0,_92);
311_secondPart=_8d.substring(_92+1);
312objj_msgSend(_object,"addObserver:forKeyPath:options:context:",_8b,_firstPart,_25,nil);
313_value=objj_msgSend(_object,"valueForKey:",_firstPart);
314if(_value){
315objj_msgSend(_value,"addObserver:forKeyPath:options:context:",_8b,_secondPart,_25,nil);
316}
317return _8b;
318}
319}),new objj_method(sel_getUid("observeValueForKeyPath:ofObject:change:context:"),function(_93,_94,_95,_96,_97,_98){
320with(_93){
321if(_96==_object){
322objj_msgSend(_observer,"observeValueForKeyPath:ofObject:change:context:",_firstPart,_object,_97,_context);
323if(_value){
324objj_msgSend(_value,"removeObserver:forKeyPath:",_93,_secondPart);
325}
326_value=objj_msgSend(_object,"valueForKey:",_firstPart);
327if(_value){
328objj_msgSend(_value,"addObserver:forKeyPath:options:context:",_93,_secondPart,_25,nil);
329}
330}else{
331objj_msgSend(_observer,"observeValueForKeyPath:ofObject:change:context:",_firstPart+"."+_95,_object,_97,_context);
332}
333}
334}),new objj_method(sel_getUid("finalize"),function(_99,_9a){
335with(_99){
336if(_value){
337objj_msgSend(_value,"removeObserver:forKeyPath:",_99,_secondPart);
338}
339objj_msgSend(_object,"removeObserver:forKeyPath:",_99,_firstPart);
340_object=nil;
341_observer=nil;
342_context=nil;
343_value=nil;
344}
345})]);
346var _50=_50=function(_9b,_9c,_9d,_9e){
347return {observer:_9b,options:_9c,context:_9d,forwarder:_9e};
348};
349var _3b=_3b=function(_9f,_a0){
350return function(_a1,_a2,_a3){
351objj_msgSend(_a1,"willChangeValueForKey:",_9f);
352_a0.method_imp(_a1,_a2,_a3);
353objj_msgSend(_a1,"didChangeValueForKey:",_9f);
354};
355};
356var _3c=_3c=function(_a4,_a5){
357return function(_a6,_a7,_a8,_a9){
358objj_msgSend(_a6,"willChange:valuesAtIndexes:forKey:",CPKeyValueChangeInsertion,objj_msgSend(CPIndexSet,"indexSetWithIndex:",_a9),_a4);
359_a5.method_imp(_a6,_a7,_a8,_a9);
360objj_msgSend(_a6,"didChange:valuesAtIndexes:forKey:",CPKeyValueChangeInsertion,objj_msgSend(CPIndexSet,"indexSetWithIndex:",_a9),_a4);
361};
362};
363var _3d=_3d=function(_aa,_ab){
364return function(_ac,_ad,_ae,_af){
365objj_msgSend(_ac,"willChange:valuesAtIndexes:forKey:",CPKeyValueChangeReplacement,objj_msgSend(CPIndexSet,"indexSetWithIndex:",_ae),_aa);
366_ab.method_imp(_ac,_ad,_ae,_af);
367objj_msgSend(_ac,"didChange:valuesAtIndexes:forKey:",CPKeyValueChangeReplacement,objj_msgSend(CPIndexSet,"indexSetWithIndex:",_ae),_aa);
368};
369};
370var _3e=_3e=function(_b0,_b1){
371return function(_b2,_b3,_b4){
372objj_msgSend(_b2,"willChange:valuesAtIndexes:forKey:",CPKeyValueChangeRemoval,objj_msgSend(CPIndexSet,"indexSetWithIndex:",_b4),_b0);
373_b1.method_imp(_b2,_b3,_b4);
374objj_msgSend(_b2,"didChange:valuesAtIndexes:forKey:",CPKeyValueChangeRemoval,objj_msgSend(CPIndexSet,"indexSetWithIndex:",_b4),_b0);
375};
376};
377i;13;CPArray+KVO.j