-
Notifications
You must be signed in to change notification settings - Fork 984
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
fix subs bug #15680
fix subs bug #15680
Conversation
Jenkins BuildsClick to see older builds (4)
|
@@ -43,7 +43,7 @@ | |||
[:f> | |||
(fn [] | |||
(let [duration (or (rf/sub [:toasts/toast-cursor id :duration]) 3000) | |||
on-dismissed #((or (rf/sub [:toasts/toast-cursor id :on-dismissed]) identity) id) | |||
on-dismissed (or (rf/sub [:toasts/toast-cursor id :on-dismissed]) identity) |
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.
this is the fix
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.
Good catch and fix @flexsurfer
@@ -80,7 +80,7 @@ | |||
(create-timer)))))] | |||
;; create auto dismiss timer, clear timer when unmount or duration changed | |||
(rn/use-effect (fn [] (create-timer) clear-timer) [duration]) | |||
(rn/use-unmount on-dismissed) | |||
(rn/use-unmount #(on-dismissed id)) |
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 pass the id
here and create the anonymous function? It's questionable because the subscription [:toasts/toast-cursor id :on-dismissed]
already returns a function that has access to the id
value and the identity
function doesn't care about any argument in this case.
I'm just wondering why it wouldn't work using just (rn/use-unmount on-dismissed)
.
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.
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.
It's just to handle situations where id and on-dismissed are both dynamically generated and hard or not elegant enough to pass the id to the on-dismissed fn.
It might be a premature optimization.
fixes #15678
sometimes you can see in re-frisk subscriptions run in the loop, that means there is a mistake in usage, and we should find and fix that
PS: actually it didn't solve the problem, so the review is on hold
PS2: fixed , so subscription must be called only by reagent when its initializing the view, but in this case it was run in the dismiss function outside of reagent context , which leads to subscription leak
ready for review