@croct/plug 0.8.0 → 0.9.0

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.
Files changed (3) hide show
  1. package/package.json +2 -3
  2. package/plug.d.ts +3 -1
  3. package/plug.js +28 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/plug",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A fully-featured devkit for building natively personalized applications.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "bundle": "rollup -c"
34
34
  },
35
35
  "dependencies": {
36
- "@croct/sdk": "^0.6.0",
36
+ "@croct/sdk": "^0.7.0",
37
37
  "tslib": "^2.2.0"
38
38
  },
39
39
  "devDependencies": {
@@ -55,7 +55,6 @@
55
55
  "jest": "^26.6.3",
56
56
  "rollup": "^2.48.0",
57
57
  "rollup-plugin-terser": "^7.0.2",
58
- "temp-dir": "^2.0.0",
59
58
  "ts-jest": "^26.5.6",
60
59
  "typescript": "^4.2.4"
61
60
  },
package/plug.d.ts CHANGED
@@ -19,6 +19,7 @@ export interface Plug extends EapFeatures {
19
19
  readonly tracker: TrackerFacade;
20
20
  readonly user: UserFacade;
21
21
  readonly session: SessionFacade;
22
+ readonly initialized: boolean;
22
23
  readonly flushed: Promise<this>;
23
24
  readonly plugged: Promise<this>;
24
25
  plug(configuration: Configuration): void;
@@ -37,10 +38,11 @@ export declare class GlobalPlug implements Plug {
37
38
  private instance?;
38
39
  private plugins;
39
40
  private initialize;
40
- private initialized;
41
+ private ready;
41
42
  constructor();
42
43
  extend(name: string, plugin: PluginFactory): void;
43
44
  plug(configuration?: Configuration): void;
45
+ get initialized(): boolean;
44
46
  get plugged(): Promise<this>;
45
47
  get flushed(): Promise<this>;
46
48
  private get sdk();
package/plug.js CHANGED
@@ -22,7 +22,7 @@ var GlobalPlug = /** @class */ (function () {
22
22
  var _this = this;
23
23
  this.pluginFactories = { playground: playground_1.factory };
24
24
  this.plugins = {};
25
- this.initialized = new Promise(function (resolve) {
25
+ this.ready = new Promise(function (resolve) {
26
26
  _this.initialize = resolve;
27
27
  });
28
28
  }
@@ -163,10 +163,17 @@ var GlobalPlug = /** @class */ (function () {
163
163
  logger.debug('Initialization complete');
164
164
  });
165
165
  };
166
+ Object.defineProperty(GlobalPlug.prototype, "initialized", {
167
+ get: function () {
168
+ return this.instance !== undefined;
169
+ },
170
+ enumerable: false,
171
+ configurable: true
172
+ });
166
173
  Object.defineProperty(GlobalPlug.prototype, "plugged", {
167
174
  get: function () {
168
175
  var _this = this;
169
- return this.initialized.then(function () { return _this; });
176
+ return this.ready.then(function () { return _this; });
170
177
  },
171
178
  enumerable: false,
172
179
  configurable: true
@@ -258,15 +265,16 @@ var GlobalPlug = /** @class */ (function () {
258
265
  };
259
266
  GlobalPlug.prototype.unplug = function () {
260
267
  return tslib_1.__awaiter(this, void 0, void 0, function () {
261
- var logger, pending, _loop_2, _a, _b, _c, pluginName, controller;
262
- var e_2, _d;
268
+ var _a, instance, plugins, logger, pending, _loop_2, _b, _c, _d, pluginName, controller;
269
+ var e_2, _e;
263
270
  var _this = this;
264
- return tslib_1.__generator(this, function (_e) {
265
- switch (_e.label) {
271
+ return tslib_1.__generator(this, function (_f) {
272
+ switch (_f.label) {
266
273
  case 0:
267
274
  if (this.instance === undefined) {
268
275
  return [2 /*return*/];
269
276
  }
277
+ _a = this, instance = _a.instance, plugins = _a.plugins;
270
278
  logger = this.sdk.getLogger();
271
279
  pending = [];
272
280
  _loop_2 = function (pluginName, controller) {
@@ -284,34 +292,35 @@ var GlobalPlug = /** @class */ (function () {
284
292
  .catch(function (error) { return logger.error("Failed to disable \"" + pluginName + "\": " + error_1.formatCause(error)); }));
285
293
  };
286
294
  try {
287
- for (_a = tslib_1.__values(Object.entries(this.plugins)), _b = _a.next(); !_b.done; _b = _a.next()) {
288
- _c = tslib_1.__read(_b.value, 2), pluginName = _c[0], controller = _c[1];
295
+ for (_b = tslib_1.__values(Object.entries(plugins)), _c = _b.next(); !_c.done; _c = _b.next()) {
296
+ _d = tslib_1.__read(_c.value, 2), pluginName = _d[0], controller = _d[1];
289
297
  _loop_2(pluginName, controller);
290
298
  }
291
299
  }
292
300
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
293
301
  finally {
294
302
  try {
295
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
303
+ if (_c && !_c.done && (_e = _b.return)) _e.call(_b);
296
304
  }
297
305
  finally { if (e_2) throw e_2.error; }
298
306
  }
307
+ // Reset
308
+ delete this.instance;
309
+ this.plugins = {};
310
+ this.ready = new Promise(function (resolve) {
311
+ _this.initialize = resolve;
312
+ });
299
313
  return [4 /*yield*/, Promise.all(pending)];
300
314
  case 1:
301
- _e.sent();
302
- _e.label = 2;
315
+ _f.sent();
316
+ _f.label = 2;
303
317
  case 2:
304
- _e.trys.push([2, , 4, 5]);
305
- return [4 /*yield*/, this.instance.close()];
318
+ _f.trys.push([2, , 4, 5]);
319
+ return [4 /*yield*/, instance.close()];
306
320
  case 3:
307
- _e.sent();
321
+ _f.sent();
308
322
  return [3 /*break*/, 5];
309
323
  case 4:
310
- delete this.instance;
311
- this.plugins = {};
312
- this.initialized = new Promise(function (resolve) {
313
- _this.initialize = resolve;
314
- });
315
324
  logger.info('🔌 Croct has been unplugged.');
316
325
  return [7 /*endfinally*/];
317
326
  case 5: return [2 /*return*/];