-
-
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
feat(Store): add action creators #1570
Conversation
Preview docs changes for b8d8099 at https://previews.ngrx.io/pr1570-b8d8099/ |
Preview docs changes for 38c78c7 at https://previews.ngrx.io/pr1570-38c78c7/ |
Preview docs changes for 447480a at https://previews.ngrx.io/pr1570-447480a/ |
Preview docs changes for 47a8041 at https://previews.ngrx.io/pr1570-47a8041/ |
Preview docs changes for 7976c89 at https://previews.ngrx.io/pr1570-7976c89/ |
Some initial feedback:
Thanks for working on this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial changes
Preview docs changes for 10412bc at https://previews.ngrx.io/pr1570-10412bc/ |
Preview docs changes for ca6d9db at https://previews.ngrx.io/pr1570-ca6d9db/ |
Preview docs changes for ee081de at https://previews.ngrx.io/pr1570-ee081de/ |
Preview docs changes for 67a692f at https://previews.ngrx.io/pr1570-67a692f/ |
Preview docs changes for 2991f70 at https://previews.ngrx.io/pr1570-2991f70/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
I left some small comments.
Could you squash the commits in to two parts?
- Add action creator
- Refactor the example app
projects/example-app/src/app/auth/actions/login-page.actions.ts
Outdated
Show resolved
Hide resolved
Preview docs changes for 8430c71 at https://previews.ngrx.io/pr1570-8430c71/ |
Preview docs changes for 0f322b3 at https://previews.ngrx.io/pr1570-0f322b3/ |
Preview docs changes for ba8c655 at https://previews.ngrx.io/pr1570-ba8c655/ |
c8fc6b9
to
c6c86c1
Compare
Preview docs changes for c8fc6b9 at https://previews.ngrx.io/pr1570-c8fc6b9/ |
Preview docs changes for c6c86c1 at https://previews.ngrx.io/pr1570-c6c86c1/ |
5685c8c
to
ec39242
Compare
Preview docs changes for 5685c8c at https://previews.ngrx.io/pr1570-5685c8c/ |
14a803f
to
52999ad
Compare
Preview docs changes for 52999ad at https://previews.ngrx.io/pr1570-52999ad/ |
Hi, one question. This feature may appear before version 8, since it does not produce a breaking change? Thank you very much in advance. |
@osnoser1 this will most likely land with V8 as we'll want to upgrade TypeScript to the latest version first, along with other changes to support this feature. |
Preview docs changes for 7d0a5ac at https://previews.ngrx.io/pr1570-7d0a5ac/ |
Preview docs changes for a3c4ee4 at https://previews.ngrx.io/pr1570-a3c4ee4/ |
Preview docs changes for 52a8470 at https://previews.ngrx.io/pr1570-52a8470/ |
Done! 😄 |
@@ -7,20 +7,12 @@ export enum AuthApiActionTypes { | |||
LoginRedirect = '[Auth/API] Login Redirect', | |||
} | |||
|
|||
export class LoginSuccess implements Action { | |||
readonly type = AuthApiActionTypes.LoginSuccess; | |||
export const AuthApiActions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having functions directly in the file would be better. You can then use named module import as a grouping mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to group them this way to take advantage of the ActionsUnion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So a few issues I have with this:
- both function and classes Action creator are allowed and welcomed. This changes to function-specific.
- according to Google's TS style guide:
When providing a structural-based implementation, explicitly include the type at the declaration of the symbol (this allows more precise type checking and error reporting).
// use
const foo: Foo = {
a: 123,
b: 'abc',
}
// instead of
const foo = {
a: 123,
b: 'abc',
}
On the other hand, I don't think anyone at Google is using function-based action creator and this proposal could be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add that this was @kolodny idea, that I iterated on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will you open a new issue with this proposal? I'd lean towards creating a new API such as withAction('type')
for this as opposed to changing Action
.
@brandonroberts may I ask you to take a second look at Blog about ts-actions: https://blog.angularindepth.com/how-to-reduce-action-boilerplate-90dc3d389e2b Lib itself: https://github.com/cartant/ts-action I think it changes my opinion about Class-based actions. If anything, I'll probably switch to that style. |
@alex-okrushko Sure. Maybe we can land this one and follow-up with a PR that add something similar to what |
@tja4472 will you rebase on master to fix the merge conflicts? |
@brandonroberts @tja4472 @timdeschryver I'd really like to remove the Enum/String Compare that to the const foo = action("FOO", payload<{ foo: number }>());
foo({foo: 5}); // create action
foo.type // statically get the type to be used in reducer or ofType() in Effect. What if we clone (with some adjustments that make sense for NgRx) the I'll be more than willing to drop my proposal from #1634 in favor of that. |
I'm in favor of having one way in comparison to having a function approach (this PR) as well as having a class approach (proposal in #1634). |
@alex-okrushko I'm open to including some form of the action creator to |
Preview docs changes for 6bba23d at https://previews.ngrx.io/pr1570-6bba23d/ |
Preview docs changes for bb2c7b6 at https://previews.ngrx.io/pr1570-bb2c7b6/ |
Preview docs changes for ee0d102 at https://previews.ngrx.io/pr1570-ee0d102/ |
@brandonroberts Rebased 😄 |
@tja4472 thanks for your time and effort on this PR, but I believe the implementation proposed by @alex-okrushko and @kolodny on the idea/library by @cartant in #1634 is the one we'll go with. |
@brandonroberts I quite understand. 👍 Thank you for your time. Looking forward to the completed #1634 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
#1480
What is the new behavior?
Adds action creators
Does this PR introduce a breaking change?
Other information