PDA

View Full Version : am I doing what everyone else is doing? shortening the method calls



blomasky
2 Oct 2013, 2:16 PM
since I am "self taught" (ok, you kids on the forum have helped me so very much, but besides the 99 books I have read and the forum for questions, I have been finding the "best practice" for myself and so far pretty darn happy)

about a zillion times (more or less) I am have to search for a component or get the selected row and instead of always typing either:

Ext.ComponentQuery.query('#itemID')[0]

or
Ext.ComponentQuery.query('#itemID')[0].getSelectionModel().getSelection()[0];

I created a "globals" class with methods like
globals.compQuery('#itemID')
and
globals.currentRow('#itemID)

I just wanna know if everyone else is saying "DUH" of course we did that. Or am I missing something? (ok, forget am I missing something, I am sure I am missing a LOT!)

p.s. I am not OVER impressed with the 4.2.2 release. I see, after 5 months, there are a whopping 3, yes, count them 3 new features, and a bunch of bug fixes... While I am sort of a noob to Sencha, it seems like the development is slowing compared to the past. Yes, this still rocks my boat, I can build a desktop replacement for a BICARSA (go ahead, all you kids under 50, look up that abbreviation, those of us with grey hair, have been doing this since umm.err. before you were born) that works fine and blazing fast (using direct and cold fusion) I mean, REAL fast with not too much effort on my part.

Bruce

p.p.s. Margarita time, so ending post.

ettavolt
2 Oct 2013, 9:53 PM
You should better create shortcuts (with caching) with controller refs (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.app.Controller-cfg-refs).
For selection you can try lastSelected (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.selection.Model-method-getLastSelected) or directy: controller.getGrid().selModel.lastSelected.
If you want to make this even shorter, consider extending Ext.app.Controller with onClassExtended specified. There you can process some custom config (say, 'selRef') and define accessors. For details see onClassExtended of Ext.app.Controller.

Don't worry so much. Master degree is obtainable only through digging source code back and force zilliard times. :) And this, obviously, requires a lot of time. For me, personally, two years was not enough - I still don't understand well charts and layouts.

blomasky
3 Oct 2013, 2:21 AM
I do use controll refs for main components (grids, forms, etc.) that I am accessing often, but, I don't list all fields / buttons / etc. that I might be referencing once or twice in my code. If I did that, my ref. section of the controller would be huge!

Maybe my old eyes, but I can not find any docs on "onClassExtended".

Bruce

eric.cook
3 Oct 2013, 6:28 AM
The "onClassExtended" method is private. On the right side of the "Config | Properties | Methods | Events" toolbar is a "Show" button. Clicking on it opens a menu for selecting which members you want to see.

To select a child component of a container by itemId, you can use the "getComponent" method of the container.

ettavolt
3 Oct 2013, 9:57 PM
I do use controll refs for main components (grids, forms, etc.) that I am accessing often, but, I don't list all fields / buttons / etc. that I might be referencing once or twice in my code. If I did that, my ref. section of the controller would be huge!
Well, not doing so blows up your methods. Specifying a ref however, has one advantage - if you change layout, you have a central place to edit your queries.