Reflux Action Not Reaching Method

29 Views Asked by At

I have build a store with actions like below:

import Reflux from 'reflux'

export const AuthActions = Reflux.createActions(['updateAuth', 'otherThing'])

export class AuthStore extends Reflux.Store
{
  constructor()
  {
    super()
    this.state = {
      authToken: null,
      authUser: null
    }
    this.listenables = AuthActions
  }

  otherThing()
  {
    debugger
    console.log("OTHER THINNGGS")
  }

  updateAuth(token, user)
  {
    debugger
    console.log("DODOODO")
    this.setState({authToken: token, authUser: user})
  }

}

However, anytime I import AuthActions and call AuthActions.otherThing() or AuthActions.updateAuth(token, user) I never reach those debuggers and nothing is printed to console, as if the methods are never called. I have tried renaming to onUpdateAuth and onOtherThing as well with no change.

1

There are 1 best solutions below

0
steventnorris On

Turns out, my store was never initialized. When you have a store, you have to either import and set the store in your component or initialize elsewhere in order to ensure the listenables are linked up to an instance of the store. In order to ensure my stores are always available, I create a single instance of the stores and exported that instead of the class itself.