goatslacker / alt

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

this.actions is undefined ? #691

Closed xtabbas closed 7 years ago

xtabbas commented 7 years ago

I just deleted and installed node_modules again and for some reason i can no longer access this.actions anymore in the Actions.js file. Here is my HomeActions.js file code :

import alt from '../../alt';
import request from 'superagent';

class HomeActions {
    constructor() {
        this.generateActions(
            'updateUserSuccess',
            'updateUserFail',
            'logoutSuccess',
            'logoutFail'
        );
    }

    getUser() {
      console.log(this); /*by console logging this i figured out there is 
          no actions object present in "this." but in the older version of my app before i 
         updated my dependencies actions object and dispatch func() were a part of "this."*/

        request
            .get('api/getuser')
            .end((err, res) => {
                this.actions.updateUserSuccess(res.text); //undefined
                //alt.actions.HomeActions.updateUserSuccess(res.text); 
               //also tried calling actions in this way but getting dispatch error
            });
      }
}

export default alt.createActions(HomeActions);

Can someone explain to me whats going on ? Thanks alot <3

goatslacker commented 7 years ago

You're probably on a newer version of alt. Try this. updateUserSuccess