Skip to content

Commit

Permalink
dont track parentValues
Browse files Browse the repository at this point in the history
  • Loading branch information
Akolyte01 committed Aug 15, 2023
1 parent 1009d3d commit 1dc5721
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/async-stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ export const asyncWritable = <S extends Stores, T>(
return currentLoadPromise as T;
};

let parentValues: StoresValues<S>;

let mostRecentLoadTracker: Record<string, never>;
const selfLoadThenSet = async () => {
const selfLoadThenSet = async (parentValues: StoresValues<S>) => {
const thisLoadTracker = {};
mostRecentLoadTracker = thisLoadTracker;

Expand Down Expand Up @@ -148,15 +146,14 @@ export const asyncWritable = <S extends Stores, T>(
// called when store receives its first subscriber
const onFirstSubscription: StartStopNotifier<T> = () => {
setCurrentLoadPromise();
parentValues = getAll(stores);
setState('LOADING');

const initialLoad = async () => {
try {
parentValues = await loadAll(stores);
const parentValues = await loadAll(stores);
ready = true;
changeReceived = false;
selfLoadThenSet();
selfLoadThenSet(parentValues);
} catch (error) {
ready = true;
changeReceived = false;
Expand All @@ -173,10 +170,10 @@ export const asyncWritable = <S extends Stores, T>(
setState('RELOADING');
}
ready = false;
parentValues = await loadAll(stores);
const parentValues = await loadAll(stores);
// eslint-disable-next-line require-atomic-updates
ready = true;
selfLoadThenSet();
selfLoadThenSet(parentValues);
}
};

Expand Down Expand Up @@ -216,7 +213,7 @@ export const asyncWritable = <S extends Stores, T>(
try {
const writeResponse = (await writePersistFunction(
newValue,
parentValues,
getAll(stores),
oldValue
)) as T;

Expand Down Expand Up @@ -260,10 +257,10 @@ export const asyncWritable = <S extends Stores, T>(

const visitMap = visitedMap ?? new WeakMap();
try {
parentValues = await reloadAll(stores, visitMap);
const parentValues = await reloadAll(stores, visitMap);
ready = true;
if (changeReceived || reloadable || wasErrored) {
selfLoadThenSet();
selfLoadThenSet(parentValues);
} else {
resolveCurrentLoad(get(thisStore));
setState('LOADED');
Expand Down

0 comments on commit 1dc5721

Please sign in to comment.