Options
You can provide a config when you create your root NgxsModule, as forRoot accepts 2 arguments. The second argument is a ModuleOptions object that can have such properties as developmentMode, compatibility and executionStrategy.
Turning on
developmentModeoption will add additional debugging features, like freezing your state and actions to guarantee immutability. Default value isfalse.compatibilityis an object that can havestrictContentSecurityPolicyproperty, if you setstrictContentSecurityPolicytotrue, then the support for the strict Content Security Policy will be enabled. This will cirumvent some optimisations that violate a strict CSP through the use ofnew Function(...). Default value isfalse.executionStrategyis an advanced option. It is used to have specific control of the way that ngxs executes code that is considered to be inside the ngxs context (ie. within@Actionhandlers) and the context under which the NGXS behaviours are observed (outside the ngxs context). These observable behaviours are:@Select(...),store.select(...),actions.subscribe(...)orstore.dispatch(...).subscribe(...)Developers who prefer to manually control the change detection mechanism in their application may choose to use the
NoopNgxsExecutionStrategy(or implement their own) which does not interfere with zones and therefore relies on the external context to handle change detection (for example:OnPushor ivy's rendering engine). The default value ofnullwill result in the default strategy being used. The default strategy runs NGXS operations outside Angular's zone but all observable behaviours of NGXS are run back inside Angular's zone. The default value isnull.
@NgModule({
imports: [
NgxsModule.forRoot(states, {
developmentMode: !environment.production,
compatibility: {
strictContentSecurityPolicy: true
},
executionStrategy: NoopNgxsExecutionStrategy
})
]
})
export class AppModule {}Last updated

