-
Notifications
You must be signed in to change notification settings - Fork 31
Added COUNTER mode for saga injectors #24
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
Conversation
Added 'COUNTER' constant for saga injectors mode property This allows developers to use single saga many times in different components pages or similar systems - Saga mounts only once, increments counter - Saga unmounts only when all of same sagas are ejected - Issues with takeLatest could appear
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.
Thanks for your contribution! Looks good but I had a few suggestions
src/sagaInjectors.js
Outdated
@@ -33,6 +41,7 @@ export function injectSagaFactory(store, isValid) { | |||
const newDescriptor = { | |||
...descriptor, | |||
mode: descriptor.mode || DAEMON, | |||
[COUNTER_PROP]: 0, |
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.
Why not just call this count
?
[COUNTER_PROP]: 0, | |
count: 0, |
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 agree, its updated as mentioned!
src/sagaInjectors.js
Outdated
|
||
// Clean up in development when mode is COUNTER | ||
if ( | ||
process.env.NODE_ENV !== 'production' && |
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.
why do we need to check if not production?
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.
TBH i don't even remember, i will make example with issue and solution
to demonstrate what this actual does
I might figure out why i did that a long time ago
meanwhile i have removed it, because non of the tests fail
- updated tests to support removal of this branch of code/logic
- `COUNTER` **[String][26]** The saga will be mounted similar to 'RESTART_ON_REMOUNT', only difference is that | ||
saga will be mounted only once on first inject, and ejected when all injectors are unmounted. | ||
So this enables you to have multiple injectors with same saga and key, only one instance of saga will run | ||
and enables you to have system that are more similar to widgets |
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.
- `COUNTER` **[String][26]** The saga will be mounted similar to 'RESTART_ON_REMOUNT', only difference is that | |
saga will be mounted only once on first inject, and ejected when all injectors are unmounted. | |
So this enables you to have multiple injectors with same saga and key, only one instance of saga will run | |
and enables you to have system that are more similar to widgets | |
- `COUNTER` **[String][26]** Similar to 'RESTART_ON_REMOUNT' except the | |
saga will be mounted only once on first inject and ejected when all injectors are unmounted. | |
This enables you to have multiple injectors with the same saga and key and only one instance of the saga will run |
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.
Thank you for help, i have updated as u suggested
now its much better!
- updated dynamic counter to count property of descriptor - updated COUNTER mode description in comments and typescript types - Removed delete part in development mode - Added tests to cover removal of injected saga in dev env
I have created example where we demonstrate how counter works |
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.
Looks good, thanks 👍
This PR does a few things:
Example
injectSaga({ key: "books", saga: booksSaga, mode: COUNTER })
I hope this helps somebody, cheers