-
Notifications
You must be signed in to change notification settings - Fork 4
add useSignalEffectWithAbortOnChange
#114
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
base: main
Are you sure you want to change the base?
Conversation
| const setupInner = (optional: OptionalSignal<any>) => { | ||
| const inner = optional.peek() | ||
| if (inner !== undefined) subscribeTo(inner, 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.
We also need to unsubscribe to the inner if the outer signal value changes from defined to undefined.
Also, no any.
| const setupInner = (optional: OptionalSignal<any>) => { | |
| const inner = optional.peek() | |
| if (inner !== undefined) subscribeTo(inner, run) | |
| } | |
| const setupInner = (optional: OptionalSignal<unknown>) => { | |
| const inner = optional.peek() | |
| if (inner === undefined) /*TODO: unsubscribe inner*/ | |
| else subscribeTo(inner, 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.
the unsubs are done at the end:
return () => {
cleanupFns.forEach(fn => fn())
abortController.abort()
}
```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.
That is too late. You need to unsubscribe from the inner signal anytime the outer signal changes to undefined. You'll then resubscribe to the inner signal when the outer signal changes back to defined. You already have the resubscribe setup correctly, but without the unsubscribe you'll end up subscribing many times. You'll also incorrectly receive update notifications when nothing has changed.
| daiApprovedForRouter.deepValue = await getAllowanceErc20Token(maybeWriteClient, DAI_TOKEN_ADDRESS, maybeWriteClient.account.address, router) | ||
| sharesApprovedToRouter.deepValue = await isErc1155ApprovedForAll(maybeWriteClient, AUGUR_SHARE_TOKEN, maybeWriteClient.account.address, router) | ||
| } | ||
| useSignalEffectWithAbortOnChange([maybeWriteClient] as const, (_abortSignal, ...params) => updateAccountSpecificSignals(...params), console.error) |
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.
You'll start using the abort later I assume? Without using the abort, I'm not sure we gain much by switching.
Co-authored-by: Micah Zoltu <[email protected]>
No description provided.