Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Squawk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export default function createStore<T>(initialState: Required<T>, useReduxDevToo

/** Ensure that subscribers are invoked only once */
const invokedSubscribers = new Set<Callback>();

// Cache the state locally so we don't recreate a copy of it for every subscriber
const currentState = globalState.get();

const reduceEach = (subscriber: Callback) => {
// Check if subscriber has been invoked
if (invokedSubscribers.has(subscriber)) {
Expand All @@ -107,7 +111,7 @@ export default function createStore<T>(initialState: Required<T>, useReduxDevToo
// Add the subscriber to the list of invoked subscribers
invokedSubscribers.add(subscriber);
// and invoke it
subscriber(globalState.get());
subscriber(currentState);
};

// Call the reducer for each list in subscribers
Expand Down
Loading