Skip to content

Commit

Permalink
subscribeWithSelector: fireImmediately after subscribing
Browse files Browse the repository at this point in the history
  • Loading branch information
devanshj committed Nov 20, 2021
1 parent 9697e01 commit 9989d11
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/middleware/subscribeWithSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ const subscribeWithSelectorImpl: ESubscribeWithSelector =
let previousSelected = currentSelected as E.Previous<ESelectedState>
const emit = () => listener(currentSelected, previousSelected)

if (fireImmediately) emit()

return parentSubscribe(() => {
let unsubscribe = parentSubscribe(() => {
let nextSelected = selector(parentGet())
if (equals(currentSelected, nextSelected)) return

previousSelected = E.previous(currentSelected)
currentSelected = nextSelected
emit()
})
if (fireImmediately) emit()

return unsubscribe
}

return storeInitializer(parentSet, parentGet, updatedParentStore)
Expand Down

0 comments on commit 9989d11

Please sign in to comment.