in packages/recoil/recoil_values/Recoil_selector.js [795:847]
function getValFromCacheAndUpdatedDownstreamDeps(
store: Store,
state: TreeState,
): ?Loadable<T> {
const depsAfterCacheDone = new Set();
const executionInfo = getExecutionInfo(store);
let cachedVal;
try {
cachedVal = cache.get(
nodeKey => {
invariant(
typeof nodeKey === 'string',
'Cache nodeKey is type string',
);
const loadable = getCachedNodeLoadable(store, state, nodeKey);
return loadable.contents;
},
{
onNodeVisit: node => {
if (node.type === 'branch' && node.nodeKey !== key) {
depsAfterCacheDone.add(node.nodeKey);
}
},
},
);
} catch (error) {
throw err(
`Problem with cache lookup for selector "${key}": ${error.message}`,
);
}
/**
* Ensure store contains correct dependencies if we hit the cache so that
* the store deps and cache are in sync for a given state. This is important
* because store deps are normally updated when new executions are created,
* but cache hits don't trigger new executions but they still _may_ signifiy
* a change in deps in the store if the store deps for this state are empty
* or stale.
*/
if (cachedVal) {
setDepsInStore(
store,
state,
depsAfterCacheDone,
executionInfo?.latestExecutionId,
);
}
return cachedVal;
}