/** * `DeferredClass` is a generic class to define the pattern of code loaded after the initial code download. * * @remarks * Example: * ``` * class DeferredFoo extends DeferredClass { * * // Static members do not inherit the generic types so we do this to correctly enforce the right typing. * public static instance() DeferredFoo { * return this._instance; * } * * public create(arg1: string, arg2: number): Foo { * return new this._classType(arg1, arg2); * } * * protected _internalLoad(): Promise { * // code to lazy load e.g. require.ensure(...) * // or import(...) * // or SPComponentLoader.loadComponentById(...).then( * // (module: typeof DeferredFooModuleType) => { return module.DeferredFoo; }); * } * } * ``` * * @param Type - The type of the Instance object. This type should define how you create an instance * of the deferred class. * @param Instance - The interface of the deferred class. * * @internal */ export default abstract class DeferredClass { /** * The singleton instance. */ private static _internalInstance; /** * Resolves after _loadPromise resolves. */ protected readonly _onAfterLoadPromise: Promise; /** * The type of the Instance object. */ protected _classType: Type; /** * The promise used for loading the code. */ protected _loadPromise: Promise; /** * Resolve callback from _onAfterLoadPromise. Invoked in DeferredClass.load after the code has loaded. */ protected _resolveOnAfterLoadCallbacks: () => void; /** * Initialize, if needed, the _internalInstance singleton. * * @returns - The singleton instance. */ protected static _getInstance(): any; /** * Instantiate an instance of Type. * * @param args - A generic argument list; should match the signature of the constructor for Type. * * @returns - An instance of Type. */ abstract create(...args: any[]): Instance; /** * @returns Whether or not the code has been loaded. */ get isLoaded(): boolean; /** * @returns Whether or not the code should load. Value should not change during the lifecycle of an instance. */ get shouldLoad(): boolean; /** * Loads the deferred chunk. After the returned promise is resolved, DeferredClass.create can be used * to create an instance of the deferred class. * * @returns - The Promise used for loading the code. If DeferredClass.shouldLoad has been overridden * and returns false, then a rejected Promise is returned. */ load(): Promise; /** * Returns a thenable Promise to be resolved after the code has finished loading. Use this for cases where * you do not want to invoke code loading but want to be notified when the code has loaded. * * @returns - A promise resolved after the code loads. */ onAfterLoad(): Promise; /** * Singleton instance. */ protected constructor(); /** * Defines how the deferred class is to be loaded asynchronous. * * @returns - The promise used for loading the code. */ protected abstract _internalLoad(): Promise; } //# sourceMappingURL=DeferredClass.d.ts.map