MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / getResourceLoading

Method getResourceLoading

lib/src/store.ts:139–177  ·  view source on GitHub ↗

* Gets a resource by URL. Fetches and parses it if it's not available in the * store. Instantly returns an empty loading resource, while the fetching is * done in the background . If the subject is undefined, an empty non-saved * resource will be returned.

(
    subject?: string,
    opts: {
      /** Won't fetch the resource if it's new */
      newResource?: boolean;
      /**
       * If this is true, incomplete resources will not be automatically
       * fetched. This limits the amount of requests. Use this for things like
       * menu items.
       */
      allowIncomplete?: boolean;
    } = {},
  )

Source from the content-addressed store, hash-verified

137 * resource will be returned.
138 */
139 getResourceLoading(
140 subject?: string,
141 opts: {
142 /** Won't fetch the resource if it's new */
143 newResource?: boolean;
144 /**
145 * If this is true, incomplete resources will not be automatically
146 * fetched. This limits the amount of requests. Use this for things like
147 * menu items.
148 */
149 allowIncomplete?: boolean;
150 } = {},
151 ): Resource | null {
152 // This is needed because it can happen that the useResource react hook is called while there is no subject passed.
153 if (subject == undefined) {
154 const newR = new Resource(unknownSubject, opts.newResource);
155 return newR;
156 }
157 const found = this.resources.get(subject);
158 if (found == undefined) {
159 const newR = new Resource(subject, opts.newResource);
160 newR.loading = true;
161 this.addResource(newR);
162 if (!opts.newResource) {
163 this.fetchResource(subject);
164 }
165 return newR;
166 } else if (!opts.allowIncomplete && found.loading == false) {
167 // In many cases, a user will always need a complete resource.
168 // This checks if the resource is incomplete and fetches it if it is.
169 if (found.get(urls.properties.incomplete)) {
170 found.loading = true;
171 this.addResource(found);
172 this.fetchResource(subject);
173 }
174 return found;
175 }
176 return found;
177 }
178
179 /**
180 * Gets a resource by URL. Fetches and parses it if it's not available in the

Callers 4

useResourceFunction · 0.80
useResourcesFunction · 0.80
store.test.tsFile · 0.80
handleDestroyFunction · 0.80

Calls 3

addResourceMethod · 0.95
fetchResourceMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected