Results 1 to 4 of 4

Thread: Listener best practice

  1. #1
    Sencha User
    Join Date
    Jul 2009
    Posts
    55
    Vote Rating
    0
      0  

    Default Listener best practice

    Is it generally considered best practice to add listeners for UI interaction (button presses/list item taps/etc) within a controller or within the views themselves?

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Kind of depends. The logic needs to be in the controller so you can put the listeners and logic in the controller. The only reason why I would say you can listen for it in a view (minus not using MVC) is to fire a custom event. I have created a container which has many children but I don't want the controller to have too intiment knowledge of how a view is structured so I have the container listen for events on it's children and then fire a custom event on itself. Then if I ever have to change the layout on that container, I only have to change the view not find where that logic is implemented in any controller.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jul 2009
    Posts
    55
    Vote Rating
    0
      0  

    Default

    That makes sense. So your controller would still listen for your custom event, but the view would handle capturing the component event and translating it to your custom event, correct?

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Yes, correct. Basically turning that container into a fully fledged widget that can handle itself apart from an application.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •