Skip to content

Commit

Permalink
Made the "shouldUpdate" true, so that updates do flow to watched asyn…
Browse files Browse the repository at this point in the history
…c actions even if useEffect hasn't run yet
  • Loading branch information
lostpebble committed Oct 10, 2020
1 parent 10d6d35 commit 61fe273
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/async.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clientStores, IPullstateAllStores, PullstateContext } from "./PullstateCore";
import React, { MutableRefObject, useContext, useEffect, useMemo, useRef, useState } from "react";
import React, { MutableRefObject, useContext, useEffect, useRef, useState } from "react";
import {
EAsyncEndTags,
EPostActionContext,
Expand Down Expand Up @@ -623,6 +623,7 @@ further looping. Fix in your cacheBreakHook() is needed.`);
cache.listeners[key] = {};
}
cache.listeners[key][watchId.current] = onAsyncStateChanged;
shouldUpdate[key][watchId.current] = true;
// console.log(`[${key}][${watchId}] Added listener (total now: ${Object.keys(cache.listeners[key]).length})`);
}

Expand Down Expand Up @@ -867,7 +868,7 @@ further looping. Fix in your cacheBreakHook() is needed.`);

const updateCached: TAsyncActionUpdateCached<A, R> = (args, updater, options) => {
const { notify = true, resetTimeCached = true, runPostActionHook: postAction = false, key: customKey } =
options || {};
options || {};

const key = _createKey(args, customKey);

Expand All @@ -888,7 +889,7 @@ further looping. Fix in your cacheBreakHook() is needed.`);
newResult,
args,
clientStores.loaded ? (clientStores.stores as S) : (storeErrorProxy as S),
EPostActionContext.CACHE_UPDATE
EPostActionContext.CACHE_UPDATE,
);
}

Expand Down Expand Up @@ -919,8 +920,8 @@ further looping. Fix in your cacheBreakHook() is needed.`);
const stores = onServer
? (useContext(PullstateContext)!.stores as S)
: clientStores.loaded
? (clientStores.stores as S)
: (storeErrorProxy as S);
? (clientStores.stores as S)
: (storeErrorProxy as S);

if (
cacheBreakHook({
Expand Down Expand Up @@ -966,7 +967,7 @@ further looping. Fix in your cacheBreakHook() is needed.`);

const delayedRun: TAsyncActionDelayedRun<A> = (
args = {} as A,
{ clearOldRun = true, delay, immediateIfCached = true, ...otherRunOptions }
{ clearOldRun = true, delay, immediateIfCached = true, ...otherRunOptions },
) => {
if (clearOldRun) {
clearTimeout(delayedRunActionTimeout);
Expand All @@ -977,7 +978,8 @@ further looping. Fix in your cacheBreakHook() is needed.`);

if (finished && !cacheBreakable) {
run(args, otherRunOptions);
return () => {};
return () => {
};
}
}

Expand Down

0 comments on commit 61fe273

Please sign in to comment.