Results 1 to 2 of 2

Thread: Ext.app.Application. Objects creation sequence and using Options Objects

  1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    22
    Answers
    3
    Vote Rating
    0
      0  

    Question Unanswered: Ext.app.Application. Objects creation sequence and using Options Objects

    Hey everyone
    I'm trying to build proper Application using Ext.application approach and forcing problem of using objects in configs(options).

    This breif example shows what I'm talking about:
    Code:
    Ext.application({
        name: 'myApp',
        controllers: ['Index']
    });
    Should create a simple app with global var myApp, right?
    Further it creates some myApp.controllers.Index var for desired Index controller.
    Code:
    Ext.define('myApp.controller.Index', {
        extend: 'Ext.app.Controller',
        stores: ['MyCustomStore'];
    
        // I create this method here to be used in several Stores and not copy-pasted there
        myCustomFunctionToHandleRestExceptions: function(response) {
         
       }
        ...
    });
    This code helps me create MyCostomStore to be used in application, right?
    Next I try to create this store
    Code:
    Ext.define('myApp.store.MyCustomStore', {
        extend: 'Ext.data.Store',
        autoLoad: true,
        proxy: {
            type: 'rest',
            url: '/myURLHere',
            reader: {
                type: 'json'
            },
            listeners: {
                exception(): function(proxy, response, operation) {
                     if (response.status == 401) {
                          // following line tries to handle 401 response using Index controller. And fails
                          myApp.getCotroller('Index').myCustomFunctionToHandleRestExceptions(response);
                     }
                }
            }
    });
    That red line fails due to myApp variable is not created at that moment and I'm trying to use it in Options object for listeners ...

    1. Which is proper/common approach for situations like that? Should I use something like initComponent method in this case instead of my attempts to pass objects via config files?

    2. Where to read the sequence of creation of all those objects (application, controller, store etc) in context of Ext.app.Application.

    Thanks

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,748
    Answers
    130
    Vote Rating
    128
      0  

    Default

    you can controll the events of stores in your controllers as well.
    there you have the application reference and it should be cleaner imho.
    Best regards
    Tobias Uhlig

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
  •