How to combine two dynamic selectors to a new selector?

355 Views Asked by At

I have the following selector

static orderFilteredByStatus(status: string){
    return createSelector([OrderState], (state: OrderStateModel) => {...}
}

Now I have another selector in a different state.

static status(name: string)
    return createSelector([DashboardState.settings], (dashboardSettings: DashboardSetting[]) => {...}
}

Now I want to combine both selectors to create a new selector so that the value of the selector status is passed to the selector ordersFilteredByStatus. Something like that:

@Selector([OrderState.orderFilteredByStatus(DashboardState.status("fixedName")])
static ordersDashboard(orders: Order[]){...}

Is that possible? I know that you could combine the selectors via switchMap() but I want a new selector combining both if that is possible. The parameter name is fixed

1

There are 1 best solutions below

0
Raul Rothschild On

You can compose selectors

@Selector([MyStateOne.getAll, MyStateTwo.getAll]) static getCombinedData()

You can see an live example of NGXS implementation of Mark WhitField (Project Lead of NGXS) here in this GH repo.

https://github.com/markwhitfeld/ngxs-diner

Orders.queries.ts has an example of this @Select() composition