Closed marcinnajder closed 6 years ago
you can take a look at my project https://github.com/sandangel/ngrx-utils using ofAction operator. Much cleaner way I think. ^^
@marcinnajder if that's the way you want to define actions, that's fine. You lose some ability to easily refactor your action types. Thanks for the example!
Thanks for comments and links!
@sandangel interesting idea with generating separate file ... action.generated.ts
I saw ngrx-actions by @amcdnl and great interview and many very good presentations from @vsavkin. Different approaches but still a lot of code to read.
Actions are very similar to discriminated unions in F#.
type BookActions =
| Search of string
| SearchComplete of Book[]
| SearchError of string
| Load of Book
| Select of string
Just look how expressive this code is. This was an inspiration for my solution. The readability is the key feature but still we have type safety, editor support, no JS code after compilation, no tool or runtime lib required.
I recommend you this video Domain Modeling Made Functional - Scott Wlaschin. It can change how you think about code :)
kind regards, marcin
Do these solutions resolve the deprecated payload impact?
all my actions are useless now since I upgraded and I need to refactor
I am not a fan of the presented way because of havin to spell out the text of action in a string when it should be nailed with an enum... leaves room for text string code errors
How exactly the definition of action is changed ? (the specific action is removed, the whole actions type (tagged union type) is removed, the shape of payload is changed, the name of action type is changed, ... )
and how often such changes are made ?
Thanks for comment
Hi
We have found a simple way of defining actions in ngrx. We are curious about your opinion.
This is all we need to do to define actions for books from your sample app.
Dispatching action looks like this:
Reducer function looks like this:
The implementation of effects may look like this:
Where
choose
is a tiny utility function:Here you can find all changes we need to make to introduce this approach to sample ngrx app
https://github.com/marcinnajder/platform/commit/838185ff53819e1a01057c4f06880368f1adb848
This way we don't have to define classes and enums for actions. We still have type safety in all places and the VS Code intellisense works correctly.
kind regards, marcin