1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    14
    Answers
    2
    Vote Rating
    0
    jcorredor is on a distinguished road

      0  

    Default Unanswered: Controllers - Good Practice?

    Unanswered: Controllers - Good Practice?


    I have an architecture question. After working with Sencha for some time I'm unsure as to what is the correct use of controllers. There are two options. The first is how I've been using them so far, which is simply to capture events and perform actions accordingly. The second is a more traditional controller, which contains the logic and functions for each view and cannot see other views.

    For example, lets say we had a navigation view and had a button to switch from the main view to the next view. In both uses, the 'tap' event of the button would be handled by the controller. However, in the first option, the main view controller would then directly display the next view. In the second option, the main view controller would get the next view's controller who would then have a function that would display its view.

    Both of these uses are possible, but which of these did the Sencha developers intend us to use as good practice?

  2. #2
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Probably both.
    In different situations one or the other ways it is a good way
    If you writing a component and you might use the Controller as the controller in mvc not as an event router necessarily.
    If you write an small application you will feel the need to use a couple of controllers~events~routers as ST2 advertise.

    In a large application you might have logic that is not directly event driven and might feel as a good idea to place it in a controller that has no refs or control thingy


    This is just my opinion

  3. #3
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    Also from my experience, I am writing very large applications and I have still managed to not use Controllers. I never got into Controllers after seeing the confusing syntax while switching from ST1 to 2. I come from a Java background and I feel applying functions directly to classes without refs or handling events without routers has been much easier.

  4. #4
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    No controllers at all Jerome?

  5. #5
    Sencha User
    Join Date
    Jun 2012
    Posts
    14
    Answers
    2
    Vote Rating
    0
    jcorredor is on a distinguished road

      0  

    Default


    It is definitely possible to make an app without controllers, but I feel like that would seem a little unreadable and disorganized.

  6. #6
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Actually I think it is impossible, mainly because Ext.app.Application extends Ext.app.Controller

  7. #7
    Sencha User
    Join Date
    Jun 2012
    Posts
    14
    Answers
    2
    Vote Rating
    0
    jcorredor is on a distinguished road

      0  

    Default


    Touché bluehipy . However, I think we've diverged from the point a little. To give you some context, the point of starting this thread in the first place is because my development team and I have to organize the way we write Sencha code for the future. You could say I'm writing company wide Sencha code standards, so I have to get it right and it needs to be generic. I know there are many possible architectures when writing applications under Sencha, I just really want to know which one is more correct so that the code we write in the future is cleaner and is less susceptible to damage by future Sencha patches. I plan to do this by knowing what model they had in mind when writing it. After all, MVC has quite a few interpretations.

  8. #8
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    @bluehipy Yeah granted the Application itself is a controller, but I do not use controllers. In the end I do have controlling functions but I do so that doesn't follow the orthodox syntax. I create a main function for my applications to handle broad helper functions, and then try to fit all other processing on the separate classes in my Js files. You can think of it more of a object structure that can be found in Java.

    To go with what jcorredor is saying, you should follow the correct syntax to be confident that future changes won't effect the code. The way I have done it did successfully merge from v1 to v2, though.

  9. #9
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Mmmm I can guess what they had in mind and I like it but I wouldn't know what future will bring. Differences from ST1 to ST2 were essential.


    I like that you said you write "Sencha code" not javascript code

    I would not be afraid of using fully what ST2 brings on the table. I am sure that future versions will improve things and if something essential will change the transition will not be dramatic to be done.

    For example if at some point controllers will not have refs and control anymore, will not be hard to re~implement it or replace them with classic event listeners.

    So if you wirte "Sencha code" follow the Sencha ways

  10. #10
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    What can I say Jerome, I love controllers because they force me to organize code better. Generally I use one for each view or group of views to handle related events. I am seeing them as a chance to keep my views really clean.


    I am sure that application ca be done without the controllers but I like to use the framework