Hi guys,
I'm playing with reactive concepts while building my simple app.
I have some main_vm with two sub-models session_vm and user_vm.
Once user changes submitLogin prop in main_vm I successfully defined a reactor which fetches session (by calling session.authenticate2() ),
in this fetch session.isValid turns to true, and I want to add to user_vm another contractor to react on this change (with fetching a user from backend),
but I don't know how to do it in a proper way without cheating (and defining some other prop in main_vm like sessionIsValid).
Here is my source faulty code with some comments, and thank you for any feedback:
glu.defModel('myapp.main', {
modelType: 'main',
session: {mtype: 'myapp.session'},
user: {mtype: 'myapp.user'},
isInProgress$: function() { return this.user.isInProgress || this.session.isInProgress },
submitLogin: false,
create: function() {
this.session = this.model('myapp.session');
this.user = this.model('myapp.user');
this.user.onSessionValid = {
on: ['this.parentVM.session.isValidChanged'], // I think the main problem is here in this path, or maybe it something else?
action: function(){
if (this.parentVM.session.isValid === true)
{
this.user.load(function(){},function(){});
}
}
}
},
login3: function(){
//this.submitLogin = true; // why this one doesn't work and I have to invoke setter directly like in the line bellow ?
this.set('submitLogin', true);
},
onSubmitLogin: {
on: ['submitLoginChanged'],
action: function(){
var me = this;
me.session.authenticate2(me.userName, me.pass,
function () {
me.session.commit();
me.session.set('isValid', me.session.isValid); // in session.authenticate2() I perform me.session.loadData(), but maybe it's not enough,
// so I'm trying to cheat (currently with no result and) to invoke setter directly?
},
function () {me.session.commit();});
}
}
}