Comments (7)
If you're using commonjs you can use exports
to get around this:
alt.createActions(ActionClass, exports)
from alt.
Another option is to use a callback.
class Actions {
constructor() {
this.generateActions('actionOne');
}
actionTwo() {
WebAPIUtils.someAsyncOp((err, data) => {
this.actions.actionOne(data);
});
}
}
from alt.
@goatslacker - thanks, that worked! Can you explain what happens behind the scenes when using alt.createActions(ActionClass, exports) ?
@troutowicz , that was the approach I was going to take as last resort, but I like goatslacker's solution better.
from alt.
The docs mention what that 2nd parameter is for: https://github.com/goatslacker/alt/blob/master/docs/createActions.md#createactions
Essentially it'll just add each action to exports. You can pass any object into createActions as its second parameter and it'll add all the actions to that object.
action.foo becomes exports.foo
Does that answer it or were you looking for a why does this work in commonjs when you use exports but not module.exports?
from alt.
I'm more curious as to why it works, but doesn't when I use module.exports.
from alt.
@jongbeau Here is a relatively short article that should help explain what is happening under the covers.
Note that not all module systems do a great job at handling circular dependencies. I typically use webpack as it handles circular dependencies well and just like Node (in the way described in the article above).
from alt.
Oh interesting didn't know that tidbit.
It works because the values get assigned to exports
later on so they'll be available at run-time when you need them.
from alt.
Related Issues (20)
- Is this still alive? HOT 2
- sequentially perform actions that require source retrieval at same time HOT 2
- Error handler does not get triggered for ajax calls HOT 4
- Wait for store function to complete
- Different tests competing in modifying the store
- Multiple input in controlled forms
- Public Method returns state not store; am I guaranteed the Store is updated when the listener fires? HOT 1
- PropTypes in React 16 Deprecated HOT 2
- dispatchIdentity rudely omit all params when the first one is undefined.
- Upgrade to Webpack 3 HOT 1
- Store not listening to actions HOT 4
- can not call DataSource function during an action
- Typescript does not work
- Using bindListeners vs Store.listen emits changes several seconds slower HOT 1
- docs specify file that does not exists
- How to test async actions
- ss state in compoennts HOT 2
- Trato de hacer la mostrar mis registros en paginas HOT 1
- Documentation needs to be fixed HOT 4
- Documentation needs to be fixed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alt.