JSON.stringify 大型对象用于类似商店的目的

问题描述 投票:0回答:0

我得到这样的状态 Observable :

这里最重要的是这一行:

map((action: any) => JSON.stringify(action)),
行动:任何只是包含所有ngrx存储属性的对象,取决于应用程序可能很小或非常大。所以有时它包含的对象对于 JSON.stringify 来说太大了,我得到了无效的字符串长度错误。

我需要一些能够深入每个对象并为最深的对象调用 JSON.stringify 的东西,这样它就不会为整个动作对象运行,因为它总是会崩溃。

 public state$: Observable<string | null> = this.store$.pipe(
    // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
    map((action: any) => JSON.stringify(action)),
    tap((state: string) => {
      if (this.last5State.length > 5) {
        this.last5State.shift();
      }

      this.last5State = [...(this.last5State as string[]), state];
    }),
    catchError((err: unknown) => {
      console.error(err);
      return of(null);
    })
  );
angular ngrx ngrx-store
© www.soinside.com 2019 - 2024. All rights reserved.