Results 1 to 6 of 6

Thread: Reuse Views With Multiple Controllers

  1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    71
    Vote Rating
    0
      0  

    Default Reuse Views With Multiple Controllers

    I am trying to reuse views with multiple controllers. The problem I run into is that the controllers are listening to the same view events. Instead of defining views in controller to I do Ext.create() within the controller init function?

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

    Default

    A controller listens to any event that is fired based on the ComponentQuery selector you provided.

    Say you have a form with some checkboxes and you want to do something with the checked event. Since you may have 100 checkboxes but the logic is the same you can use one selector:

    Code:
    this.control({
        'formpanel checkboxfield' : {
            checked : someFn
        }
    });
    That will listen to any checkboxfield that is a child of a formpanel no matter when it is created. So you can remove and add checkboxfields and formpanels all day and this code should still listen to them
    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
    Jun 2011
    Posts
    71
    Vote Rating
    0
      0  

    Default

    So if you have multiple instances of a view the controller should listen to events from all of those instances. If you setup a reference in the controller it should know which instance the event was fired from? So all that too say I could just use the one controller for each instance of those views?

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

    Default

    Yes, anything that matches that selector will be listened to. The first argument of a listener will be the component firing the event.

    I usually don't architect my controllers based on a view... I have controllers based on feature/function. Technically you can have just one controller but that isn't very good application architecture.
    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

  5. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    71
    Vote Rating
    0
      0  

    Default

    I am trying to reuse code. I have multiple tabs that serve up similar content ( list > detail ) so the functionality will be the same for each. Would you still create multiple views for each tab of content even though it is the same?

  6. #6
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Vote Rating
    1271
      0  

    Default

    A tabpanel has to have multiple instances. You can use the same component but separate content. Then your controller action will most likely be the same.
    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

Tags for this Thread

Posting Permissions

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