diff --git a/packages/xhr-http-handler/src/xhr-http-handler.ts b/packages/xhr-http-handler/src/xhr-http-handler.ts index 9bfc015e45f0..a5637056a4e0 100644 --- a/packages/xhr-http-handler/src/xhr-http-handler.ts +++ b/packages/xhr-http-handler/src/xhr-http-handler.ts @@ -73,6 +73,19 @@ export class XhrHttpHandler extends EventEmitter implements HttpHandler; + /** + * @returns the input if it is an HttpHandler of any class, + * or instantiates a new instance of this handler. + */ + public static create(instanceOrOptions?: HttpHandler | XhrHttpHandlerOptions) { + if (typeof (instanceOrOptions as any)?.handle === "function") { + // is already an instance of HttpHandler. + return instanceOrOptions as HttpHandler; + } + // input is ctor options or undefined. + return new XhrHttpHandler(instanceOrOptions as XhrHttpHandlerOptions); + } + public constructor(options?: XhrHttpHandlerOptions | Provider) { super(); if (typeof options === "function") {