goatslacker / alt

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

ES6 imports not available in Store methods. #602

Closed christopherdbull closed 8 years ago

christopherdbull commented 8 years ago

I have the following Store:

'use strict';
import alt from 'components/Dispatcher';
import SessionActions from 'actions/SessionActions';
import {loginUser} from 'services/UserService';

export class SessionStore {

  constructor() {
    console.log(loginUser);
    this.bindListeners({
      createSession: SessionActions.CREATE_SESSION
    });
  }

  createSession(data){
    loginUser(data).done(
      function(data){
        window.localStorage.setItem('session', data.data);
        this.emitChange();
      }
    ).fail(function(){
      window.localStorage.removeItem('session');
    });
  }

  //override store output
  output(state){
    window.localStorage.getItem('session');
  }
}

export default alt.createStore(SessionStore, 'SessionStore');

When I log the loginUser function in the constructor, however when it's called as part of an Action it is null. Am I missing something? Do I need to bind in dependencies somehow?

Thanks

mattlo commented 8 years ago

You should post product support on StackOverflow with the alt and flux tag http://stackoverflow.com/questions/tagged/alt http://stackoverflow.com/questions/tagged/flux.

ES6 imports are resolved before alt invocations (in your example), most likely this is an issue with your named exports. To test, just create a non alt impl with the same imports and call loginUser. I'm using lodash named imports everywhere with no problems at all.

christopherdbull commented 8 years ago

@mattlo thanks.