Hybrid View

  1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    391
    Vote Rating
    2
    parky128 is on a distinguished road

      0  

    Default Referencing the application instance in a View

    Referencing the application instance in a View


    Hi,

    Under PR3 I was able to set a global variable for my Application instance so I could reference it from functions defined in some of my views.

    So for example, in my Application launch function I could do:

    Code:
    MyAppName.app = this;
    And then in a function in my view I could then get to some other globals defined in my Application class such as:

    Code:
    MyAppName.app.selectedUntID
    But MyAppName.app is coming up as undefined for me in PR4 now. I know I get an 'application' variable in the Controller class, can I achieve this in my View classes?

  2. #2
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    529
    Vote Rating
    17
    estesbubba will become famous soon enough

      0  

    Default


    We have a rule with our Sencha MVC development that views know nothing about controllers (and application is a controller). In your case I would make a singleton class that views/controllers/application can all access. The alternative would be for your view to fire a custom event that the application listens to and makes the changes.

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Posts
    391
    Vote Rating
    2
    parky128 is on a distinguished road

      0  

    Default


    Ok, I must be coding this in a poor way....

    In my application class I am defining some globals like so:

    Code:
    Ext.application({
    		name: 'MyApp',
    		controllers: ['Login','MainView','Unit','GMap','History', 'Preferences', 'HistoryCriteria','LogoutAction'],
    		models: ['UserPreferences','TrackingList','CurrentGrid','History','Journey', 'Placemarker'],
    		stores: ['UserPreferences','TrackingListWithShowAll','TrackingList','CurrentGrid','History','Journey', 'Placemarkers'],
    		userIsLoggedIn: false,
    		wsClient:null,
    		loginWin: null,
    		loadMask: null,
    		sessionDataLoaded: false,
    		waitingForSessionCheckResponse: false,
    		launch: function() {
    		
    		....
    From what your saying, I should probably have any globals reside in this singleton class correct?

  4. #4
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    529
    Vote Rating
    17
    estesbubba will become famous soon enough

      0  

    Default


    I like the idea of a singleton for global application data. Our application classes are pretty dumb mainly defining name, controllers, and launch.

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    4
    bweiler is on a distinguished road

      0  

    Default


    Quote Originally Posted by estesbubba View Post
    We have a rule with our Sencha MVC development that views know nothing about controllers (and application is a controller). In your case I would make a singleton class that views/controllers/application can all access. The alternative would be for your view to fire a custom event that the application listens to and makes the changes.
    I think keeping the architecture clean is a good goal. However, it is not clear how to accomplish some tasks such as firing an event from a view to a controller. I'm still using the following hack to do this.

    The listener is defined in the controller:
    Code:
    this.getApplication().on({
        geocoded: function(){console.log("geocode event fired");},
        ...
    });
    I need to fire the event from the view. However, views don't know about applications, so I have to use a global variable.
    Code:
    globals.application.fireEvent('geocoded');
    What is the recommended approach to firing application events from views?

    Thanks

  6. #6
    Sencha User
    Join Date
    Jun 2009
    Posts
    391
    Vote Rating
    2
    parky128 is on a distinguished road

      0  

    Default


    How did you define your globals variable so the rest of the app could see it?

  7. #7
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    4
    bweiler is on a distinguished road

      0  

    Default


    I just used the app namespace. This is not a great idea, but it is an easy workaround to some of the object reference issues.

    MyApp.globals (or whatever you like that won't result in a namespace collision)

  8. #8
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,337
    Vote Rating
    75
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Views should never access an application. They should only fire events and the controllers should react to those events.

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar