No more VSTS.
Monday, December 3, 2018
ghetto actions in the Redux pattern
Instead of having objects like this, an older approach is to just have magic strings for the actions. Either way they get used in case/switch logic in the reducers to find the right function.
.of in Observables
In contrast to the usual holding open of an ear, this is going to get something for an Observable once and then be done with it. It is like using an Observable as a promise. http://rxmarbles.com this has some details on the machinery of the various Observables keywords and it really shows off how simple .of is.
Addendum 12/5/2018: .of will actually take whatever is handed into it and then make an Observable out of it so that you may hand a promise to an Observable that will run once in this manner but otherwise what I suggest above is bad.
"changing" store objects in Angular Redux while not mutating state
There are a couple of ways to ensure a new object with a new pointer.
- the spread operator
- Object.Assign
- deep copy
- the "deep clone merge function" of redux.utility.ts which has a lot of wacky rules and exception cases and maybe should be avoided
Addendum 12/4/2018: Item 4 above is bad. The lodash way could serve as a replacement however:
var foo = _cloneDeep(bar);
Addendum 12/6/2018: should be cloneDeep not _cloneDeep
the @Effect decorator and the trailing dollar sign naming convention
The side effect model for the @ngrx way to go for Redux can be found here. You are going to use the @Effect decorator with this stuff like so:
@Effect() handleFailure$: Observable<any>;
...and like so:
@Effect({dispatch:false}) handleFailure$: Observable<any>;
You need the {dispatch:false} when you have an effect that does not kick off another action. Also note that the trailing dollar sign naming convention denotes that a variable is an Observable. In jQuery a leading dollar sign at a variable name denotes a DOM element by convention, but in this case we have rhyming names for all of the Observables in lieu of alliteration.
.map versus .switchMap
Beyond what .map does .switchMap will do some flattening so that if you are mapping to Observables and you are mapping Observables of Foo, Bar, Baz, and Quz you will not get Observables of Observables of Foo, Bar, Baz, and Quz but instead just Observables of Foo, Bar, Baz, and Quz. The nesting is ironed away.