TIL, 2022-07-28, TS class as interface
Why must must NGRX/Redux effects return actions? Is using a noop action like elm considered bad practice?
{ dispatch: false }
to opt out of@Effects
. Under the hood, this is achieved with theignoreElements
operator.- Effect conditionally:
@Effect() foo$ = this.actions$
.ofType(ChatActions.FOO)
.withLatestFrom(this.store, (action, state) => ({ action, state }))
.mergeMap(({ action, state }) => {
if (state.foo.isCool) {
return Observable.of({ type: Actions.BAR });
} else {
return Observable.empty();
}
});
Typescript: Use class as interface
class Test {
foo: any;
private bar: any;
}
class SpecialTest implements Pick<Test, keyof Test> {
foo: any;
}
- This saves writing a base interface type. Can just write the mock interface based on the original one.