-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Single createSelector function doesn't get state passed in. #1558
Comments
I think this was an undesired outcome, due to implementing the selector with props feature (more specifically to allow the createSelector with only a props selector. The PR #1515 reverts this change, but was indeed a breaking change. |
With the knowledge gained, I think it wasn't a great idea to allow these selectors with props working directly with the projection function without the need of a selector. Concrete this means that the following won't be possible anymore const getTodosById = createSelector(
(state: TodoAppSchema, id: number) => {
return state.todos.find(p => p.id === id);
}
); But would need to be written as: const getTodosById = createSelector(
(state: TodoAppSchema) => state,
(state: TodoAppSchema, id: number) => {
return state.todos.find(p => p.id === id);
}
);
// or
const getTodosById = createSelector(
(state: TodoAppSchema) => state.todos,
(todos: Todo[], id: number) => {
return todos.find(p => p.id === id);
}
); This would also be in line with the reduxjs/reselect library which has as API This would be a breaking change that we could add for v8. Would this be OK for you @brandonroberts ? To clarify, this would also mean that the example snippet would also be an invalid selector and would lead to errors (as pre v6.1.2):
|
@timdeschryver I'm fine with the breaking change to make the usage more consistent. |
👍 I will submit a PR |
Closes #1558 BREAKING CHANGE: Selectors with only a projector function aren't valid anymore. This change will make the usage more consistent. BEFORE: ``` const getTodosById = createSelector( (state: TodoAppSchema, id: number) => state.todos.find(p => p.id === id) ); ``` AFTER: ``` const getTodosById = createSelector( (state: TodoAppSchema) => state.todos, (todos: Todo[], id: number) => todos.find(p => p.id === id) ); ```
Hello,
This took me some time to find but I've ran into this issue.
When I have only simple selector
It will not get the state passed in.
I've found that this PR: #1515 has introduced this issue.
Not very sure why the function is not called with state as an argument but it broke my application immediately.
Minimal reproduction of the bug/regression with instructions:
Expected behavior:
Nothing should be broken by a not-breaking release.
Use of createSelector without any previous selectors is broken.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
Other information:
I would be willing to submit a PR to fix this issue
[ ] Yes (Assistance is provided if you need help submitting a pull request)
[ X] No. I think reverting the previous PR should be done. And a proper fix for the issue it was intented to fix
The text was updated successfully, but these errors were encountered: