Skip to content

Commit

Permalink
(fix) Simplify createGlobalStore mock
Browse files Browse the repository at this point in the history
  • Loading branch information
brandones committed Aug 11, 2023
1 parent 33f4a16 commit c2ec280
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions packages/framework/esm-framework/mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,17 @@ export function createGlobalStore<T>(
name: string,
initialState: T
): StoreApi<T> {
const available = availableStores[name];

if (available) {
if (available.active) {
console.error(
"Cannot override an existing store. Make sure that stores are only created once."
);
} else {
available.value.setState(initialState, true);
}

available.active = true;
return available.value;
} else {
const store = createStore<T>()(() => initialState);
initialStates[name] = initialState;
// We ignore whether there's already a store with this name so that tests
// don't have to worry about clearing old stores before re-creating them.
const store = createStore<T>()(() => initialState);
initialStates[name] = initialState;

availableStores[name] = {
value: store,
active: true,
};
availableStores[name] = {
value: store,
active: true,
};

return instrumentedStore(name, store);
}
return instrumentedStore(name, store);
}

export function getGlobalStore<T>(
Expand Down

0 comments on commit c2ec280

Please sign in to comment.