Adrian Faciu
Principal software engineer. Focused on front-end. Learning something new each day. Building things at WeVideo.
@NgModule({
imports: [
StoreModule.forRoot(reducers, {
runtimeChecks: {
strictImmutability: true,
strictStateSerializability: true,
strictActionSerializability: true,
},
}),
],
})
export class AppModule {}
Scaffolding library for Angular applications using NgRx libraries
npm install @ngrx/schematics -D
ng generate @ngrx/schematics:store State
--root --module app.module.ts
ng generate @ngrx/schematics:effect App
--root --module app.module.ts
ng generate @ngrx/schematics:action user
ng generate @ngrx/schematics:store State
--root --module app.module.ts
ng generate @ngrx/schematics:effect App
--root --module app.module.ts
ng generate @ngrx/schematics:action user
ng config cli.defaultCollection @ngrx/schematics
ng generate action user
interface EntityState<V> {
ids: string[] | number[];
entities: { [id: string | id: number]: V };
}
interface State extends EntityState<User> {
selectedUserId: number | null;
}
const adapter: EntityAdapter<User>
= createEntityAdapter<User>();
export function debug(reducer: ActionReducer<any>){
return function(state, action) {
console.log('state', state);
console.log('action', action);
return reducer(state, action);
};
}
export const metaReducers: MetaReducer<any>[] = [debug];
@NgModule({
imports: [
StoreModule.forRoot(reducers, { metaReducers })
],
})
export class AppModule {}
Use the 'real' Store
export const selectTotal = createSelector(
selectSumEvenNums,
selectSumOddNums,
(evenSum, oddSum) => evenSum + oddSum
);
describe('My Selectors', () => {
it('should calc selectTotal', () => {
expect(selectTotal.projector(2, 3)).toBe(5);
});
});
By Adrian Faciu
More topics that we can look into during the workshop.
Principal software engineer. Focused on front-end. Learning something new each day. Building things at WeVideo.