declare const UniqueId: string; declare type Loader = () => Promise; export declare type Result = any; /** * A generic resource: given some method to asynchronously load a value - the loader() * argument - it allows accessing the state of the resource. */ export declare class Resource { private error; private loader; private promise; private result; private state; constructor(loader: Loader); /** * Loads the resource if necessary. */ load(): Promise; /** * Returns the result, if available. This can be useful to check if the value * is resolved yet. */ get(): T | null | undefined; /** * This is the key method for integrating with React Suspense. Read will: * - "Suspend" if the resource is still pending (currently implemented as * throwing a Promise, though this is subject to change in future * versions of React) * - Throw an error if the resource failed to load. * - Return the data of the resource if available. */ read(): T | null; } /** * A helper method to create a resource, intended for dynamically loading code. * * Example: * ``` * // Before rendering, ie in an event handler: * const resource = JSResource('Foo', () => import('./Foo.js)); * resource.load(); * * // in a React component: * const Foo = resource.read(); * return ; * ``` * * @param {*} moduleId A globally unique identifier for the resource used for caching * @param {*} loader A method to load the resource's data if necessary */ export default function JSResource(moduleId: typeof UniqueId, loader: Loader): Resource; export {};