有没有办法将对ngrx存储的引用传递给(插件)组件?

时间:2017-04-14 01:40:04

标签: javascript typescript nativescript ngrx frp

也许我做错了。我想要做的是让我的动作有效负载传递对应用商店的引用,以及在使用异步操作完成组件时要分派的动作实例。

我的另一个选择是传递一个observable,订阅它......但是,当我尝试这样做时:

this.store.dispatch(new actions.SnackbarActionShow({
    message: 'Would you like to know the answer!',
    actionTitle: 'Yes',
    answerMessage: 'Well too bad, I\'m not telling.',
    store: this.store, // this causes error
    actionToEmit: new actions.SnackbarActionClicked(),
});

我得到错误Attempted to assign to readonly property.,而其他一切正常。我可以分配actionToEmit等等。所以,我在思考,我们无法通过引用真正通过商店,只能注入它...但我不能,因为这是{N}插件用完node_modules。最终目标是让组件从商店中调度操作......

有什么好方法吗?

编辑:

尝试做回调,但这很奇怪。只是传递一个回调会在引发action.payload未定义时引发错误,即使该变量不在回调函数的范围内。但是,如果我尝试在回调中发送新动作。我可以记录得很好。

@Effect() public snackbarActionShow$ = this.actions$
.ofType(aa.SnackbarActionTypes.ACTION_SHOW)
.map((action) => {
  const callback = () => {
      this.log.debug('called back');
      this.store.dispatch( new aa.SnackbarActionClicked() );
  };
  this.snackbar.showAction(action.payload, callback);
  return new aa.SnackbarNoOp();
});

0 个答案:

没有答案