In Mystore, this refer to Alt, rather than MyStore
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 312
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
Research direction
Start with app.js, then compare how PolicyActions and PolicyStore are created and how addDomainObject is dispatched. Reproduce the console output and trace the action-to-store binding; done means documenting the cause and confirming the expected PolicyStore context or identifying the required usage change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100