mercredi 21 janvier 2015

Global controller passing data to many different ViewModels

I'm in the process of attempting to convert a 4.x appliction to 5.x and I'm trying to figure out the right way to handle global data in the application.

In 4.x, my process was:

1. On application load, ajax call to the server to load user information

2. On user information load, fire a userLoaded event on the application



Code:



me.getApplication().fireEvent('userLoaded', data);

3. Several controllers listen to this 'userLoaded' event using Application Actions.

Code:



application.on({
userLoaded: {
fn: this.onUserLoaded,
scope: this
}

I'm not sure the "right" way to do this in 5.x. So far I have

1. Top level Controller "User"

2. On init() on "Controller.User", make ajax call to get user information


How would I then populate the data I get back from this ajax call into different ViewModels that are dependent on this information?


For example, I'm binding the name to my MainViewModel which has the ViewPort



Code:



Ext.define('MyApp.view.main.MainViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.mainmain',


data: {
name: 'Needs To Be Bind Value For Name Returned From User Load'
}


});

In architect, I've attempted to add a Application Action to the respective ViewController, but nothing happens. Is there a better way of handling this scenario?

Thanks in advance.






Global controller passing data to many different ViewModels

Aucun commentaire:

Enregistrer un commentaire