Search code examples
angulartypescriptngrx

What property is exposed to outside when using const { }


I follow the example of ngrx store as follows

https://stackblitz.com/edit/angular-multiple-entities-in-same-state?file=src%2Fapp%2Fstate%2Freducers%2Fexample.reducer.ts

There is a code in example.reducer.ts

export const { selectAll: selectAllCars } = adapterCar.getSelectors();

And the outside calls

export const selectAllCars = createSelector(selectCarState, fromExample.selectAllCars);

Not call selectAll

Sorry to ask but I have no idea how to search it. Could you please explain how it works?


Solution

  • It's a destructuring assignment. It's supposed to improve code readibility, but I wonder if it isn't misused here.

    export const { selectAll: selectAllCars } = adapterCar.getSelectors();
    

    means the same as

    const carSelectors = adapterCar.getSelectors();
    const selectAllCars = carSelectors.selectAll;
    export { selectAllCars };