Giter VIP home page Giter VIP logo

Comments (7)

goatslacker avatar goatslacker commented on May 22, 2024

If you're using commonjs you can use exports to get around this:

alt.createActions(ActionClass, exports)

from alt.

troutowicz avatar troutowicz commented on May 22, 2024

Another option is to use a callback.

class Actions {
  constructor() {
    this.generateActions('actionOne');
  }

  actionTwo() {
    WebAPIUtils.someAsyncOp((err, data) => {
      this.actions.actionOne(data);
    });
  }
}

from alt.

jongbeau avatar jongbeau commented on May 22, 2024

@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.

goatslacker avatar goatslacker commented on May 22, 2024

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.

jongbeau avatar jongbeau commented on May 22, 2024

I'm more curious as to why it works, but doesn't when I use module.exports.

from alt.

jdlehman avatar jdlehman commented on May 22, 2024

@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.

goatslacker avatar goatslacker commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.