Skip to content

Commit

Permalink
Always assume subscriptions will return sub count from current key (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Feb 27, 2023
1 parent 2464ed5 commit 3b04acf
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions subscription/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ export const subscription = (<Data, Error>(useSWRNext: SWRHook) =>
return () => {
// Prevent frequent unsubscribe caused by unmount
setTimeout(() => {
// TODO: Throw error during development if count is undefined.
const count = subscriptions.get(subscriptionKey)
if (count == null) return
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const count = subscriptions.get(subscriptionKey)! - 1

subscriptions.set(subscriptionKey, count - 1)
subscriptions.set(subscriptionKey, count)

// Dispose if it's the last one.
if (count === 1) {
if (!count) {
const dispose = disposers.get(subscriptionKey)
dispose?.()
}
Expand Down

0 comments on commit 3b04acf

Please sign in to comment.