1. #1
    Sencha User
    Join Date
    May 2009
    Posts
    135
    Vote Rating
    1
    DiscoBoy is on a distinguished road

      0  

    Question Unanswered: Store should listen to login/logout events (Best practice?)

    Unanswered: Store should listen to login/logout events (Best practice?)


    Hi,

    as example I have an user store which should load/update its content based on user login/logout events. Currently I setup the event listening in the overriden store constructor like this:

    Code:
    Ext.define('MyApp.store.app.User', {
        extend: 'Ext.data.Store',
        model: 'MyApp.model.app.User',
        autoLoad: true,
        autoSync: true,
        // We override the constructor to add a listener for login events to this store
        constructor: function () {
            this.isContructing = true;
            Ext.data.Store.prototype.constructor.apply(this, arguments);
            MyApp.comm.app.on({
                login: function() {
                    // Reload the store when user logs in but sync any unsaved items before
                    this.sync();
                    this.load();
                },
                beforelogout: function() {
                    // Try to sync all changes before we're flushing the store on  user logout
                    this.sync();
                    this.removeAll();
                },
                scope: this
            });
            this.isContructing = false;
        }
    });
    Now I'm not sure if there exists any better approach instead of overwriting the store constructor?

    MyApp.comm.app is my "global application event bus" where login & logout events are fired. Listening in controllers for these events might lead to several view components (configured with this store) receiving those events and therefore triggering store reloading a multiple times. Therefore I moved the event listening to the store itself.

    Thanks for any comments or suggestions!

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,791
    Answers
    3465
    Vote Rating
    833
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Using MVC this would be easy to fire a login and logout event on the application instance and let the controllers listen for it so your application logic would be in the controller
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    May 2009
    Posts
    135
    Vote Rating
    1
    DiscoBoy is on a distinguished road

      0  

    Default


    I know. But if i have for instance two grids configured with my user store and make them listening to logins, than both grids trigger a store reload (when only one reload is needed). or?

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,791
    Answers
    3465
    Vote Rating
    833
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Yeah, I wouldn't mess with the grid in the application event listener, would just do what I need on the store and since there is one store, any widgets attached to it will update.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    May 2009
    Posts
    135
    Vote Rating
    1
    DiscoBoy is on a distinguished road

      0  

    Default


    Thx for your comments. I think then this is the way I continue...

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi