Skip to content

Commit b4d99ee

Browse files
⚡ [performance] Optimize pendingSubscribersInternal allocation (#29)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: johnstrand <11484777+johnstrand@users.noreply.github.com>
1 parent e525c29 commit b4d99ee

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/Squawk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ export default function createStore<T>(initialState: Required<T>, useReduxDevToo
271271
}
272272

273273
// Invoke all unique subscribers with the new pending states
274-
pendingSubscribersInternal.forEach((subscriber) => subscriber(pendingState.get()));
274+
if (pendingSubscribersInternal.size > 0) {
275+
const currentPendingState = pendingState.get();
276+
pendingSubscribersInternal.forEach((subscriber) => subscriber(currentPendingState));
277+
}
275278
},
276279
/** Sets up a subscription for a single global state context */
277280
subscribe<TContext extends StoreProp>(context: TContext, callback: Callback<TStore[TContext]>): () => void {

0 commit comments

Comments
 (0)