我有两个类PizzasState和ToppingsState。 PizzaState已经具有选择器来选择披萨。
@State<PizzaStateModel>({
name: 'pizzas',
defaults: initialState
})
export class PizzasState {
constructor(private pizzaService: PizzasService) {
}
@Selector([RouterState])
static getSelectedPizza(
state: PizzaStateModel,
routerState: RouterStateModel<RouterStateParams>
): Pizza {
const pizzaId = routerState.state && routerState.state.params.pizzaId;
return pizzaId && state.entities[pizzaId];
}
@Selector()
getPizzaVisualized(state: PizzaStateModel): Pizza {
//
// what is here?
//
}
}
并且ToppingsState选择了Toppings
@State({
name: 'toppings',
defaults: initialState
})
export class ToppingsState {
constructor(private toppingsService: ToppingsService) {
}
@Selector()
static selectedToppings(state: ToppingsStateModel): number[] {
return state.selectedToppings;
}
现在,我想将选定的比萨与选定的配料一起加入,并获得可视化的比萨。
如何正确重用getSelectedPizza和getSelectedToppings? 谢谢
答案 0 :(得分:1)
您似乎需要使用joining selector。
@Selector([ToppingsState.selectedToppings])
getPizzaVisualized(state: PizzaStateModel, selectedToppings: number[]): Pizza {
// User data from both states.
}