-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I create a selector that takes an argument? #11
Comments
You have a few options. First, you can write a fuction that creates a selector. Building on the example in the readme, let's say you wanted to make the affordable products selector configurable: Selector<AppState, List<Product>> createAffordableProductsSelector(double price) {
return createSelector1(
productsSelector,
(products) => products.where((product) => product.price < price),
);
}
// Usage
final affordableProductsSelector = createAffordableProductsSelector(10.00);
final affordableProducts = affordableProductsSelector(appState); The other option: Although a selector only takes in 1 parameter, that parameter can be anything you want. It can be a class that holds multiple values, or a Dart 3 record. typedef Params = (AppState state, double price);
final affordableProductsSelector = createSelector1<Params, (List<Product>, double), List<Product>>(
(params) => (productsSelector(params.$2), params.$2),
(result) => result.$1.where((product) => product.price < result.$2),
); |
Great answer, I think it would be helpful to add this to the README - see my pull request. I amended the second example - I'm pretty sure it should be |
As the title says, how do I create a selector that takes an argument? just like this in ReselectJS
The text was updated successfully, but these errors were encountered: