storeFreeze和ngrx8

时间:2019-07-12 09:31:08

标签: angular ngrx ngrx-store angular8

我只是想升级到ngrx / store版本8。我注意到ng更新已删除了storeFreeze的所有情况。还将其从metaReducer中删除。

所以我的问题是-为什么

将storeFreeze与ngrx 8一起使用是否有问题?

在ngrx8之前:

import { ActionReducerMap, MetaReducer } from '@ngrx/store';
import { storeFreeze } from 'ngrx-store-freeze';
import * as fromGroupMember from './group-member.reducer';
import * as fromDirectoryForm from './directory-filter-form.reducer';

export const metaReducers: MetaReducer<IState>[] =
(localStorage && localStorage.getItem('production') === 'false') ? [storeFreeze] : [];

之后:

import { ActionReducerMap, MetaReducer } from '@ngrx/store';

import * as fromGroupMember from './group-member.reducer';
import * as fromDirectoryForm from './directory-filter-form.reducer';

export const metaReducers: MetaReducer<IState>[] =
(localStorage && localStorage.getItem('production') === 'false') ? [] : [];

2 个答案:

答案 0 :(得分:1)

8.0.0-rc.1上添加了迁移,以删除ngrx-store-freeze的用法,如下:

  

我们大多数用户可能正在使用ngrx-store-freeze来   防止状态突变。我们内置了运行时检查功能   版本8来防止这些攻击。

请参见github issue

答案 1 :(得分:1)

如果运行ng update @ngrx/store,则这是迁移的一部分。 还应该添加runtime checks作为替代,因为它现在是ngrx的一部分:

@NgModule({
  imports: [
    StoreModule.forRoot(reducers, {
      runtimeChecks: {
        strictStateImmutability: true,
        strictActionImmutability: true,
      },
    }),
  ],
})
export class AppModule {}