Thursday, December 6, 2018

createSelector allows for memoization of selectors in the Angular Redux way of doing things.

I offer some notes on Redux selectors, their params, and their memoization stolen from a better blog posting. The better blog posting is here. It offers this example of using params with selectors:

this.counter = this.store.pipe(
   select(fromRoot.getCount, { multiply: 2 })
);

 
 

An example of the memoization is:

export const getCount = () =>
   createSelector(
      (state, props) => state.counter[ props.id],
      (counter, props) => counter * props.multiply
   );

 
 

Some of the curious template-side markup Tim Deschryver gives for finding a customer by id (once the customers are available) and then showing it's name is:

{{ (customers | async)(id).name }}

 
 

RxJS stands for Reactive Extensions in JavaScript. I kinda thought the rx in RxJS and NgRx might be short for Redux, but that is not the prescription.

No comments:

Post a Comment