【问题标题】:Reflux Action Not Reaching Method回流作用未达到方法
【发布时间】:2018-08-29 13:21:24
【问题描述】:

我已经建立了一个具有以下操作的商店:

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})
  }

}

但是,每当我导入AuthActions 并调用AuthActions.otherThing() 或AuthActions.updateAuth(token, user) 时,我永远不会接触到那些调试器,也不会向控制台打印任何内容,就好像从未调用过这些方法一样。我也尝试重命名为onUpdateAuth 和onOtherThing,没有任何变化。

【问题讨论】:

    标签: react-native refluxjs


    【解决方案1】:

    事实证明,我的商店从未初始化过。当你有一个 store 时,你必须在你的组件中导入和设置 store 或者在其他地方初始化,以确保可监听链接到 store 的实例。为了确保我的商店始终可用,我创建了商店的单个实例并将其导出而不是类本身。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      • 2016-11-08
      • 2015-10-18
      • 1970-01-01
      • 2023-04-04
      • 2016-08-07
      • 1970-01-01
      相关资源
      最近更新 更多