MCPcopy
hub / github.com/facebook/react / accessResult

Function accessResult

packages/react-devtools-shared/src/devtools/cache.js:94–121  ·  view source on GitHub ↗
(
  resource: any,
  fetch: Input => Thenable<Value>,
  input: Input,
  key: Key,
)

Source from the content-addressed store, hash-verified

92}
93
94function accessResult<Input, Key, Value>(
95 resource: any,
96 fetch: Input => Thenable<Value>,
97 input: Input,
98 key: Key,
99): Thenable<Value> {
100 const entriesForResource = getEntriesForResource(resource);
101 const entry = entriesForResource.get(key);
102 if (entry === undefined) {
103 const thenable = fetch(input);
104 thenable.then(
105 value => {
106 const fulfilledThenable: FulfilledThenable<Value> = (thenable: any);
107 fulfilledThenable.status = 'fulfilled';
108 fulfilledThenable.value = value;
109 },
110 error => {
111 const rejectedThenable: RejectedThenable<Value> = (thenable: any);
112 rejectedThenable.status = 'rejected';
113 rejectedThenable.reason = error;
114 },
115 );
116 entriesForResource.set(key, thenable);
117 return thenable;
118 } else {
119 return entry;
120 }
121}
122
123export function createResource<Input, Key, Value>(
124 fetch: Input => Thenable<Value>,

Callers 2

readFunction · 0.70
preloadFunction · 0.70

Calls 5

getEntriesForResourceFunction · 0.85
fetchFunction · 0.85
setMethod · 0.80
getMethod · 0.65
thenMethod · 0.65

Tested by

no test coverage detected