Open jeffbski opened 7 years ago
Prior to redux-logic, my business logic was scattered about in a variety of different places including:
In addition, I relied heavily on batched actions, where logic entry points would stimulate multiple actions in one procedural chunk of code.
Needless to say, this was less than ideal. Even tools like redux-dev-tools could not give me adequate insight into "what was stimulating what"!
All of these techniques have now been replaced with "true" business logic, organizing all my logic in one isolated spot, all orchestrated by redux-logic!
My business logic is now:
Thank you redux-logic for a most excellent approach to organizing my business logic! I would highly recommend this package to anyone using the redux framework!
I stumbled onto redux-logic by complete accident, and it's been a revelation on how to approach "real" react/redux applications in an environment where deadlines, delivery, and customer satisfaction matter.
Hard business logic like making API calls (which is rarely explained well for beginners) is perfectly encapsulated in redux-logic modules, async/await is used and encouraged, and any logic that was residing in action creators, reducers, or middleware has been completely removed.
Can't enough nice things about this library-- give it a try! It can live alongside your existing solution for a POC.
I'm in the early stages of a project and we were using sagas for our async operations. It worked well enough, but was really not pleasant for anyone on my team to read. I think we all just breathed a collective sigh of relief after deciding to switch to redux-logic.
I'll have more to say as we continue using it, but our code looks so much cleaner now after porting everything over (easy migration btw). Thank you.
We're using redux-logic at Zensurance.
Redux-logic enforces great structure for our async action handlers while allowing us to do async any way we want. The validation hooks are essential for controlling user flow throughout our app, and were easy to setup and test.
I've been using redux-logic for 3 months, and I migrated my code from redux-thunk. Here are some thoughts. Pros:
Cons:
This library is just a big helper around rxjs. There are many options that are not needed. E.g. I never use processOptions
.
You must call done
. I think it's redundant in some cases.
waitFor #42 was the biggest problem for me. I had to do some hacks: For example:
dispatch({type: FOO}); // there is a synchronous logic for FOO
await Promise.delay(1); // the logic for FOO will be completed because it's synchronous
getState(); // do something with updated state
or just extract common code from 2 logics
since it's a big helper, some features are not available directly.
For example:
SET_KEYWORD
is dispatched when a textbox is changed.
searchLogic
listens for SET_KEYWORD
and fetches some items from the API.
Let's say you need to add a 500ms debounce. The action must hit your reducer, so they keyword
is updated, but only the logic is debounced.
Exactly like this example https://jsfiddle.net/jeffbski/78vpf92k/ but I use a controllable input.
Currently, it's not possible because a debounce
option debounces both logic and reducer.
I had to create two logics.
onKeywordChangeLogic
dispatch just START_SEARCH
.
searchLogic
listens for START_SEARCH
and it has a debounce
option.
You still need to know rxjs. For example: when doing more complex cancellation or when implementing waitFor
(some member suggested it).
I picked redux-logic because I had no time to learn rxjs. Recently, I used rxjs in another project, and I think I should have used redux-observable instead of redux-logic.
In this competitive world of JS libraries, many people won't even look at something unless there are compelling testimonials by other users, so I'd like to add some of your comments to the redux-logic home page to encourage others to give it a try.
If you would be willing to leave a short 1-2 sentence testimonial comment along with your name and any title/company that you want included then I'll add those to the README. You can add those as a comments on this issue or if you would rather email me, that's fine too. My email is available off the github profile here
Thanks in advance!