goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 323 forks source link

In Mystore, this refer to Alt, rather than MyStore #627

Open huqianghui opened 8 years ago

huqianghui commented 8 years ago

When I trigger the action to add domain object, why this refer to Alt, not the PolicyStore?

Below is my code.

app.js

var Alt = require('alt'); //console.log(Alt) var alt = new Alt();

module.exports = alt;


my Action: import alt from '../app';

 class PolicyActions {


addDomainObject(modelName, objectCode, scopeObject) {

var payload = {};

payload.modelName = modelName;

payload.objectCode = objectCode;

payload.scopeObject = scopeObject;

this.dispatch(payload);
 }



}



module.exports = alt.createActions(PolicyActions);


myStore

import alt from '../app';
 class PolicyStore {


constructor() {
 let policy = {};
 let allObjects = [];

this.bindListeners({
 

addDomainObject: PolicyActions.addDomainObject,

});
 }


addDomainObject(payload) {

console.log("**addDomainObject..");

console.log(this);

}

}



module.exports = alt.createStore(PolicyStore, "PolicyStore");


When I trigger the action to add domain object, Why this refer to Alt, not the PolicyStore?

huqianghui commented 8 years ago

I have to use this.getInstance() to get policyStore's reference?

Is there any advise or suggestion?

Best Regards.

Andy.hu