@dereekb/browser 10.2.0 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -2219,51 +2219,45 @@ $$1({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, {
2219
2219
  }
2220
2220
  });
2221
2221
 
2222
- /******************************************************************************
2223
- Copyright (c) Microsoft Corporation.
2224
-
2225
- Permission to use, copy, modify, and/or distribute this software for any
2226
- purpose with or without fee is hereby granted.
2227
-
2228
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2229
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2230
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2231
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2232
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2233
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2234
- PERFORMANCE OF THIS SOFTWARE.
2235
- ***************************************************************************** */
2236
-
2237
- function __awaiter(thisArg, _arguments, P, generator) {
2238
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2239
- return new (P || (P = Promise))(function (resolve, reject) {
2240
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2241
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2242
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2243
- step((generator = generator.apply(thisArg, _arguments || [])).next());
2244
- });
2245
- }
2246
-
2247
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2248
- var e = new Error(message);
2249
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2250
- };
2251
-
2252
2222
  /**
2253
2223
  * Used for loading services in the browser that are imported from other scripts, such as Facebook, Segment, Stripe, etc.
2254
2224
  */
2225
+
2226
+ function _await(value, then, direct) {
2227
+ if (direct) {
2228
+ return then ? then(value) : value;
2229
+ }
2230
+ if (!value || !value.then) {
2231
+ value = Promise.resolve(value);
2232
+ }
2233
+ return then ? value.then(then) : value;
2234
+ }
2235
+ function _call(body, then, direct) {
2236
+ if (direct) {
2237
+ return then ? then(body()) : body();
2238
+ }
2239
+ try {
2240
+ var result = Promise.resolve(body());
2241
+ return then ? result.then(then) : result;
2242
+ } catch (e) {
2243
+ return Promise.reject(e);
2244
+ }
2245
+ }
2255
2246
  class AbstractAsyncWindowLoadedService {
2256
2247
  /**
2257
2248
  * @param _windowKey Key that is attached to the window for the object that is the service when finished loading.
2258
2249
  * @param _callbackKey Optional key attached to window that is a function that is executed when the setup is complete.
2259
2250
  */
2260
- constructor(_windowKey, _callbackKey, _serviceName = _windowKey, preload = true) {
2261
- this._windowKey = _windowKey;
2262
- this._callbackKey = _callbackKey;
2263
- this._serviceName = _serviceName;
2251
+ constructor(_windowKey, _callbackKey, _serviceName = _windowKey, preload) {
2252
+ this._windowKey = void 0;
2253
+ this._callbackKey = void 0;
2254
+ this._serviceName = void 0;
2264
2255
  this._loading = new rxjs.BehaviorSubject(undefined);
2265
2256
  this.loading$ = this._loading.pipe(rxjs$1.tapFirst(() => this.loadService()), rxjs$1.filterMaybe(), rxjs.shareReplay(1));
2266
2257
  this.service$ = this.loading$.pipe(rxjs.switchMap(x => rxjs.from(x)), rxjs.shareReplay(1));
2258
+ this._windowKey = _windowKey;
2259
+ this._callbackKey = _callbackKey;
2260
+ this._serviceName = _serviceName;
2267
2261
  if (preload) {
2268
2262
  // Begin loading the service immediately.
2269
2263
  setTimeout(() => this.loadService().catch());
@@ -2316,15 +2310,18 @@ class AbstractAsyncWindowLoadedService {
2316
2310
  // override in parent if needed.
2317
2311
  }
2318
2312
  completeLoadingService() {
2319
- return __awaiter(this, void 0, void 0, function* () {
2320
- yield this._prepareCompleteLoadingService();
2321
- const service = window[this._windowKey];
2322
- if (!service) {
2323
- throw new Error(`Service "${this._serviceName}" could not complete loading.`);
2324
- }
2325
- // Init the API
2326
- const initializedService = yield this._initService(service);
2327
- return initializedService !== null && initializedService !== void 0 ? initializedService : service;
2313
+ const _this = this;
2314
+ return _call(function () {
2315
+ return _await(_this._prepareCompleteLoadingService(), function () {
2316
+ const service = window[_this._windowKey];
2317
+ if (!service) {
2318
+ throw new Error(`Service "${_this._serviceName}" could not complete loading.`);
2319
+ }
2320
+ // Init the API
2321
+ return _await(_this._initService(service), function (initializedService) {
2322
+ return initializedService != null ? initializedService : service;
2323
+ });
2324
+ });
2328
2325
  });
2329
2326
  }
2330
2327
  _prepareCompleteLoadingService() {
package/index.esm.js CHANGED
@@ -2223,7 +2223,7 @@ class AbstractAsyncWindowLoadedService {
2223
2223
  * @param _windowKey Key that is attached to the window for the object that is the service when finished loading.
2224
2224
  * @param _callbackKey Optional key attached to window that is a function that is executed when the setup is complete.
2225
2225
  */
2226
- constructor(_windowKey, _callbackKey, _serviceName = _windowKey, preload = true) {
2226
+ constructor(_windowKey, _callbackKey, _serviceName = _windowKey, preload) {
2227
2227
  this._windowKey = _windowKey;
2228
2228
  this._callbackKey = _callbackKey;
2229
2229
  this._serviceName = _serviceName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/browser",
3
- "version": "10.2.0",
3
+ "version": "11.0.1",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -16,7 +16,7 @@ export declare abstract class AbstractAsyncWindowLoadedService<T> implements Des
16
16
  * @param _windowKey Key that is attached to the window for the object that is the service when finished loading.
17
17
  * @param _callbackKey Optional key attached to window that is a function that is executed when the setup is complete.
18
18
  */
19
- constructor(_windowKey: string, _callbackKey?: string | undefined, _serviceName?: string, preload?: boolean);
19
+ constructor(_windowKey: string, _callbackKey?: string | undefined, _serviceName?: string, preload?: Maybe<boolean>);
20
20
  destroy(): void;
21
21
  getService(): Promise<T>;
22
22
  protected loadService(): Promise<T>;