NGRX 8 Effect 无限期地触发

NGRX 8 Effect fires indefinitely

我是 NGRX 的新手。我尝试创建一个简单的测试操作,其效果仅将 123 打印到控制台,但是当我打开浏览器时,我看到该效果无限期地触发(它一次又一次地打印 123)。

这是我的代码(是的,我将所有逻辑放在一个文件中,仅用于测试目的):

import {Component, Injectable, OnInit} from '@angular/core';
import {createAction, createReducer, on, Store} from '@ngrx/store';
import {Actions, createEffect, ofType} from '@ngrx/effects';
import {tap} from 'rxjs/operators';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  constructor(private store: Store<AppState>) {
  }

  ngOnInit() {
    this.store.dispatch(test());
  }

}

interface AppState {

}

const test = createAction('[Test] Test');

export const reducer = createReducer(
  {},
  on(test, state => state)
);

@Injectable()
export class Effects {

  test$ = createEffect(() => this.actions$.pipe(
    ofType(test),
    tap(() => console.log(123))
  ));

  constructor(private actions$: Actions) {
  }

}

我做错了什么?

您需要添加以下内容:{ dispatch: false } 目前您只是在记录。

查看文档 here