I'm looking for some guidance on the actual usage of lazy selectors vs dynamic selectors in NGXS. I understand the difference in syntax but I'm actually unclear on where I should prefer one over the other since both allow passing arguments to a selector. Are there any performance gains to be had in one case or the other? I've read the appropriate documentation but feel like I still don't get it.
See this snippet from this Stackblitz for a lazy selector followed by the same selector in dynamic form.
export class ZooStateQueries {
@Selector([ZooState.animals])
static animalOfType(animals: string[]) {
return (type: string) => {
return animals.filter(s => s.indexOf(type) > -1);
};
}
static animalOfType_Alternative(type: string) {
return createSelector([ZooState.animals], (animals: string[]) => {
return animals.filter(s => s.indexOf(type) > -1);
});
}
}
No actual usage issue, more of a clarification question. Thank you for any help!