piral-debug-utils 0.14.14-beta.3765 → 0.14.14-beta.3767

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/esm/emulator.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { PiletRequester } from 'piral-base';
2
2
  import { EmulatorConnectorOptions } from './types';
3
- export declare function installPiletsEmulator(requestPilets: PiletRequester, options: EmulatorConnectorOptions): void;
3
+ export declare function withEmulatorPilets(requestPilets: PiletRequester, options: EmulatorConnectorOptions): PiletRequester;
package/esm/emulator.js CHANGED
@@ -1,77 +1,77 @@
1
1
  import { isfunc, setupPilet } from 'piral-base';
2
2
  import { freezeRouteRefresh, DebugRouteSwitch } from './DebugRouteSwitch';
3
- export function installPiletsEmulator(requestPilets, options) {
3
+ export function withEmulatorPilets(requestPilets, options) {
4
4
  const { loadPilet, createApi, injectPilet, integrate, piletApiFallback = '/$pilet-api' } = options;
5
5
  // check if pilets should be loaded
6
6
  const loadPilets = sessionStorage.getItem('dbg:load-pilets') === 'on';
7
7
  const noPilets = () => Promise.resolve([]);
8
8
  const requester = loadPilets ? requestPilets : noPilets;
9
- integrate({
9
+ integrate === null || integrate === void 0 ? void 0 : integrate({
10
10
  components: {
11
11
  RouteSwitch: DebugRouteSwitch,
12
12
  },
13
- requester() {
14
- const promise = requester();
15
- // the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
16
- const piletApi = window['dbg:pilet-api'] || piletApiFallback;
17
- // either take a full URI or make it an absolute path relative to the current origin
18
- const initialTarget = /^https?:/.test(piletApi)
19
- ? piletApi
20
- : `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
21
- const updateTarget = initialTarget.replace('http', 'ws');
22
- const ws = new WebSocket(updateTarget);
23
- const timeoutCache = {};
24
- const timeout = 150;
25
- const appendix = fetch(initialTarget)
26
- .then((res) => res.json())
27
- .then((item) => (Array.isArray(item) ? item : [item]));
28
- ws.onmessage = ({ data }) => {
29
- const hardRefresh = sessionStorage.getItem('dbg:hard-refresh') === 'on';
30
- if (!hardRefresh) {
31
- // standard setting is to just perform an inject
32
- const meta = JSON.parse(data);
33
- const name = meta.name;
34
- // like a debounce; only one change of the current pilet should be actively processed
35
- clearTimeout(timeoutCache[name]);
36
- // some bundlers may have fired before writing to the disk
37
- // so we give them a bit of time before actually loading the pilet
38
- timeoutCache[name] = setTimeout(() => {
39
- // we should make sure to only refresh the page / router if pilets have been loaded
40
- const unfreeze = freezeRouteRefresh();
41
- // tear down pilet
42
- injectPilet({ name });
43
- // load and evaluate pilet
44
- loadPilet(meta).then((pilet) => {
45
- try {
46
- if (isfunc(injectPilet)) {
47
- injectPilet(pilet);
48
- }
49
- // setup actual pilet
50
- setupPilet(pilet, createApi);
51
- // disable route cache, should be zero again and lead to route refresh
52
- unfreeze();
53
- }
54
- catch (error) {
55
- console.error(error);
56
- }
57
- });
58
- }, timeout);
59
- }
60
- else {
61
- location.reload();
62
- }
63
- };
64
- return promise
65
- .catch((err) => {
66
- console.error(`Requesting the pilets failed. We'll continue loading without pilets (DEBUG only).`, err);
67
- return [];
68
- })
69
- .then((pilets) => appendix.then((debugPilets) => {
70
- const debugPiletNames = debugPilets.map((m) => m.name);
71
- const feedPilets = pilets.filter((m) => !debugPiletNames.includes(m.name));
72
- return [...feedPilets, ...debugPilets];
73
- }));
74
- },
75
13
  });
14
+ return () => {
15
+ const promise = requester();
16
+ // the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
17
+ const piletApi = window['dbg:pilet-api'] || piletApiFallback;
18
+ // either take a full URI or make it an absolute path relative to the current origin
19
+ const initialTarget = /^https?:/.test(piletApi)
20
+ ? piletApi
21
+ : `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
22
+ const updateTarget = initialTarget.replace('http', 'ws');
23
+ const ws = new WebSocket(updateTarget);
24
+ const timeoutCache = {};
25
+ const timeout = 150;
26
+ const appendix = fetch(initialTarget)
27
+ .then((res) => res.json())
28
+ .then((item) => (Array.isArray(item) ? item : [item]));
29
+ ws.onmessage = ({ data }) => {
30
+ const hardRefresh = sessionStorage.getItem('dbg:hard-refresh') === 'on';
31
+ if (!hardRefresh) {
32
+ // standard setting is to just perform an inject
33
+ const meta = JSON.parse(data);
34
+ const name = meta.name;
35
+ // like a debounce; only one change of the current pilet should be actively processed
36
+ clearTimeout(timeoutCache[name]);
37
+ // some bundlers may have fired before writing to the disk
38
+ // so we give them a bit of time before actually loading the pilet
39
+ timeoutCache[name] = setTimeout(() => {
40
+ // we should make sure to only refresh the page / router if pilets have been loaded
41
+ const unfreeze = freezeRouteRefresh();
42
+ // tear down pilet
43
+ injectPilet({ name });
44
+ // load and evaluate pilet
45
+ loadPilet(meta).then((pilet) => {
46
+ try {
47
+ if (isfunc(injectPilet)) {
48
+ injectPilet(pilet);
49
+ }
50
+ // setup actual pilet
51
+ setupPilet(pilet, createApi);
52
+ // disable route cache, should be zero again and lead to route refresh
53
+ unfreeze();
54
+ }
55
+ catch (error) {
56
+ console.error(error);
57
+ }
58
+ });
59
+ }, timeout);
60
+ }
61
+ else {
62
+ location.reload();
63
+ }
64
+ };
65
+ return promise
66
+ .catch((err) => {
67
+ console.error(`Requesting the pilets failed. We'll continue loading without pilets (DEBUG only).`, err);
68
+ return [];
69
+ })
70
+ .then((pilets) => appendix.then((debugPilets) => {
71
+ const debugPiletNames = debugPilets.map((m) => m.name);
72
+ const feedPilets = pilets.filter((m) => !debugPiletNames.includes(m.name));
73
+ return [...feedPilets, ...debugPilets];
74
+ }));
75
+ };
76
76
  }
77
77
  //# sourceMappingURL=emulator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,UAAU,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC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AAC,CAAC,MAAM,EAAE,EAAE,CACf,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;YAC5B,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACvD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3E,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,WAAW,CAAC,CAAC;QACzC,CAAC,CAAC,CACH,CAAC;IACN,CAAC,CAAC;AACJ,CAAC"}
package/esm/types.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { FC } from 'react';
2
- import type { Pilet, PiletApiCreator, PiletLoader, PiletMetadata, PiletRequester } from 'piral-base';
2
+ import type { Pilet, PiletApiCreator, PiletLoader, PiletMetadata } from 'piral-base';
3
3
  export interface EmulatorConnectorOptions {
4
4
  createApi: PiletApiCreator;
5
5
  loadPilet: PiletLoader;
6
6
  injectPilet?(pilet: Pilet): void;
7
7
  piletApiFallback?: string;
8
- integrate(components: EmulatorComponents): void;
8
+ integrate?(components: EmulatorComponents): void;
9
9
  }
10
10
  export interface ChangeSet {
11
11
  state?: boolean;
@@ -16,7 +16,6 @@ export interface ChangeSet {
16
16
  }
17
17
  export interface EmulatorComponents {
18
18
  components: Record<string, FC>;
19
- requester: PiletRequester;
20
19
  }
21
20
  export interface DebugComponents {
22
21
  wrappers: Record<string, FC>;
package/lib/emulator.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { PiletRequester } from 'piral-base';
2
2
  import { EmulatorConnectorOptions } from './types';
3
- export declare function installPiletsEmulator(requestPilets: PiletRequester, options: EmulatorConnectorOptions): void;
3
+ export declare function withEmulatorPilets(requestPilets: PiletRequester, options: EmulatorConnectorOptions): PiletRequester;
package/lib/emulator.js CHANGED
@@ -1,81 +1,81 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.installPiletsEmulator = void 0;
3
+ exports.withEmulatorPilets = void 0;
4
4
  const piral_base_1 = require("piral-base");
5
5
  const DebugRouteSwitch_1 = require("./DebugRouteSwitch");
6
- function installPiletsEmulator(requestPilets, options) {
6
+ function withEmulatorPilets(requestPilets, options) {
7
7
  const { loadPilet, createApi, injectPilet, integrate, piletApiFallback = '/$pilet-api' } = options;
8
8
  // check if pilets should be loaded
9
9
  const loadPilets = sessionStorage.getItem('dbg:load-pilets') === 'on';
10
10
  const noPilets = () => Promise.resolve([]);
11
11
  const requester = loadPilets ? requestPilets : noPilets;
12
- integrate({
12
+ integrate === null || integrate === void 0 ? void 0 : integrate({
13
13
  components: {
14
14
  RouteSwitch: DebugRouteSwitch_1.DebugRouteSwitch,
15
15
  },
16
- requester() {
17
- const promise = requester();
18
- // the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
19
- const piletApi = window['dbg:pilet-api'] || piletApiFallback;
20
- // either take a full URI or make it an absolute path relative to the current origin
21
- const initialTarget = /^https?:/.test(piletApi)
22
- ? piletApi
23
- : `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
24
- const updateTarget = initialTarget.replace('http', 'ws');
25
- const ws = new WebSocket(updateTarget);
26
- const timeoutCache = {};
27
- const timeout = 150;
28
- const appendix = fetch(initialTarget)
29
- .then((res) => res.json())
30
- .then((item) => (Array.isArray(item) ? item : [item]));
31
- ws.onmessage = ({ data }) => {
32
- const hardRefresh = sessionStorage.getItem('dbg:hard-refresh') === 'on';
33
- if (!hardRefresh) {
34
- // standard setting is to just perform an inject
35
- const meta = JSON.parse(data);
36
- const name = meta.name;
37
- // like a debounce; only one change of the current pilet should be actively processed
38
- clearTimeout(timeoutCache[name]);
39
- // some bundlers may have fired before writing to the disk
40
- // so we give them a bit of time before actually loading the pilet
41
- timeoutCache[name] = setTimeout(() => {
42
- // we should make sure to only refresh the page / router if pilets have been loaded
43
- const unfreeze = (0, DebugRouteSwitch_1.freezeRouteRefresh)();
44
- // tear down pilet
45
- injectPilet({ name });
46
- // load and evaluate pilet
47
- loadPilet(meta).then((pilet) => {
48
- try {
49
- if ((0, piral_base_1.isfunc)(injectPilet)) {
50
- injectPilet(pilet);
51
- }
52
- // setup actual pilet
53
- (0, piral_base_1.setupPilet)(pilet, createApi);
54
- // disable route cache, should be zero again and lead to route refresh
55
- unfreeze();
56
- }
57
- catch (error) {
58
- console.error(error);
59
- }
60
- });
61
- }, timeout);
62
- }
63
- else {
64
- location.reload();
65
- }
66
- };
67
- return promise
68
- .catch((err) => {
69
- console.error(`Requesting the pilets failed. We'll continue loading without pilets (DEBUG only).`, err);
70
- return [];
71
- })
72
- .then((pilets) => appendix.then((debugPilets) => {
73
- const debugPiletNames = debugPilets.map((m) => m.name);
74
- const feedPilets = pilets.filter((m) => !debugPiletNames.includes(m.name));
75
- return [...feedPilets, ...debugPilets];
76
- }));
77
- },
78
16
  });
17
+ return () => {
18
+ const promise = requester();
19
+ // the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
20
+ const piletApi = window['dbg:pilet-api'] || piletApiFallback;
21
+ // either take a full URI or make it an absolute path relative to the current origin
22
+ const initialTarget = /^https?:/.test(piletApi)
23
+ ? piletApi
24
+ : `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
25
+ const updateTarget = initialTarget.replace('http', 'ws');
26
+ const ws = new WebSocket(updateTarget);
27
+ const timeoutCache = {};
28
+ const timeout = 150;
29
+ const appendix = fetch(initialTarget)
30
+ .then((res) => res.json())
31
+ .then((item) => (Array.isArray(item) ? item : [item]));
32
+ ws.onmessage = ({ data }) => {
33
+ const hardRefresh = sessionStorage.getItem('dbg:hard-refresh') === 'on';
34
+ if (!hardRefresh) {
35
+ // standard setting is to just perform an inject
36
+ const meta = JSON.parse(data);
37
+ const name = meta.name;
38
+ // like a debounce; only one change of the current pilet should be actively processed
39
+ clearTimeout(timeoutCache[name]);
40
+ // some bundlers may have fired before writing to the disk
41
+ // so we give them a bit of time before actually loading the pilet
42
+ timeoutCache[name] = setTimeout(() => {
43
+ // we should make sure to only refresh the page / router if pilets have been loaded
44
+ const unfreeze = (0, DebugRouteSwitch_1.freezeRouteRefresh)();
45
+ // tear down pilet
46
+ injectPilet({ name });
47
+ // load and evaluate pilet
48
+ loadPilet(meta).then((pilet) => {
49
+ try {
50
+ if ((0, piral_base_1.isfunc)(injectPilet)) {
51
+ injectPilet(pilet);
52
+ }
53
+ // setup actual pilet
54
+ (0, piral_base_1.setupPilet)(pilet, createApi);
55
+ // disable route cache, should be zero again and lead to route refresh
56
+ unfreeze();
57
+ }
58
+ catch (error) {
59
+ console.error(error);
60
+ }
61
+ });
62
+ }, timeout);
63
+ }
64
+ else {
65
+ location.reload();
66
+ }
67
+ };
68
+ return promise
69
+ .catch((err) => {
70
+ console.error(`Requesting the pilets failed. We'll continue loading without pilets (DEBUG only).`, err);
71
+ return [];
72
+ })
73
+ .then((pilets) => appendix.then((debugPilets) => {
74
+ const debugPiletNames = debugPilets.map((m) => m.name);
75
+ const feedPilets = pilets.filter((m) => !debugPiletNames.includes(m.name));
76
+ return [...feedPilets, ...debugPilets];
77
+ }));
78
+ };
79
79
  }
80
- exports.installPiletsEmulator = installPiletsEmulator;
80
+ exports.withEmulatorPilets = withEmulatorPilets;
81
81
  //# sourceMappingURL=emulator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAChE,yDAA0E;AAG1E,SAAgB,qBAAqB,CAAC,aAA6B,EAAE,OAAiC;IACpG,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IACnG,mCAAmC;IACnC,MAAM,UAAU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AC,CAAC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3E,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,WAAW,CAAC,CAAC;QACzC,CAAC,CAAC,CACH,CAAC;IACN,CAAC,CAAC;AACJ,CAAC;AAvFD,gDAuFC"}
package/lib/types.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { FC } from 'react';
2
- import type { Pilet, PiletApiCreator, PiletLoader, PiletMetadata, PiletRequester } from 'piral-base';
2
+ import type { Pilet, PiletApiCreator, PiletLoader, PiletMetadata } from 'piral-base';
3
3
  export interface EmulatorConnectorOptions {
4
4
  createApi: PiletApiCreator;
5
5
  loadPilet: PiletLoader;
6
6
  injectPilet?(pilet: Pilet): void;
7
7
  piletApiFallback?: string;
8
- integrate(components: EmulatorComponents): void;
8
+ integrate?(components: EmulatorComponents): void;
9
9
  }
10
10
  export interface ChangeSet {
11
11
  state?: boolean;
@@ -16,7 +16,6 @@ export interface ChangeSet {
16
16
  }
17
17
  export interface EmulatorComponents {
18
18
  components: Record<string, FC>;
19
- requester: PiletRequester;
20
19
  }
21
20
  export interface DebugComponents {
22
21
  wrappers: Record<string, FC>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-debug-utils",
3
- "version": "0.14.14-beta.3765",
3
+ "version": "0.14.14-beta.3767",
4
4
  "description": "Utilities for debugging Piral instances.",
5
5
  "keywords": [
6
6
  "piral",
@@ -38,12 +38,12 @@
38
38
  "test": "echo \"Error: run tests from root\" && exit 1"
39
39
  },
40
40
  "devDependencies": {
41
- "piral-base": "0.14.14-beta.3765"
41
+ "piral-base": "0.14.14-beta.3767"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "piral-base": "0.14.x",
45
45
  "react": ">=16.8.0",
46
46
  "react-router": ">=5.0.0"
47
47
  },
48
- "gitHead": "f933f63d8d746f6f592e6d62a4f74921d8fbcc01"
48
+ "gitHead": "dc6b4718c8d6c7b17bf3262cbdbf97bf0a4b779e"
49
49
  }
package/src/emulator.ts CHANGED
@@ -2,90 +2,91 @@ import { isfunc, PiletRequester, setupPilet } from 'piral-base';
2
2
  import { freezeRouteRefresh, DebugRouteSwitch } from './DebugRouteSwitch';
3
3
  import { EmulatorConnectorOptions } from './types';
4
4
 
5
- export function installPiletsEmulator(requestPilets: PiletRequester, options: EmulatorConnectorOptions) {
5
+ export function withEmulatorPilets(requestPilets: PiletRequester, options: EmulatorConnectorOptions): PiletRequester {
6
6
  const { loadPilet, createApi, injectPilet, integrate, piletApiFallback = '/$pilet-api' } = options;
7
7
  // check if pilets should be loaded
8
8
  const loadPilets = sessionStorage.getItem('dbg:load-pilets') === 'on';
9
9
  const noPilets: PiletRequester = () => Promise.resolve([]);
10
10
  const requester = loadPilets ? requestPilets : noPilets;
11
11
 
12
- integrate({
12
+ integrate?.({
13
13
  components: {
14
14
  RouteSwitch: DebugRouteSwitch,
15
15
  },
16
- requester() {
17
- const promise = requester();
18
-
19
- // the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
20
- const piletApi = window['dbg:pilet-api'] || piletApiFallback;
16
+ });
21
17
 
22
- // either take a full URI or make it an absolute path relative to the current origin
23
- const initialTarget = /^https?:/.test(piletApi)
24
- ? piletApi
25
- : `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
26
- const updateTarget = initialTarget.replace('http', 'ws');
27
- const ws = new WebSocket(updateTarget);
28
- const timeoutCache = {};
29
- const timeout = 150;
18
+ return () => {
19
+ const promise = requester();
30
20
 
31
- const appendix = fetch(initialTarget)
32
- .then((res) => res.json())
33
- .then((item) => (Array.isArray(item) ? item : [item]));
21
+ // the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
22
+ const piletApi = window['dbg:pilet-api'] || piletApiFallback;
34
23
 
35
- ws.onmessage = ({ data }) => {
36
- const hardRefresh = sessionStorage.getItem('dbg:hard-refresh') === 'on';
24
+ // either take a full URI or make it an absolute path relative to the current origin
25
+ const initialTarget = /^https?:/.test(piletApi)
26
+ ? piletApi
27
+ : `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
28
+ const updateTarget = initialTarget.replace('http', 'ws');
29
+ const ws = new WebSocket(updateTarget);
30
+ const timeoutCache = {};
31
+ const timeout = 150;
37
32
 
38
- if (!hardRefresh) {
39
- // standard setting is to just perform an inject
40
- const meta = JSON.parse(data);
41
- const name = meta.name;
33
+ const appendix = fetch(initialTarget)
34
+ .then((res) => res.json())
35
+ .then((item) => (Array.isArray(item) ? item : [item]));
42
36
 
43
- // like a debounce; only one change of the current pilet should be actively processed
44
- clearTimeout(timeoutCache[name]);
37
+ ws.onmessage = ({ data }) => {
38
+ const hardRefresh = sessionStorage.getItem('dbg:hard-refresh') === 'on';
45
39
 
46
- // some bundlers may have fired before writing to the disk
47
- // so we give them a bit of time before actually loading the pilet
48
- timeoutCache[name] = setTimeout(() => {
49
- // we should make sure to only refresh the page / router if pilets have been loaded
50
- const unfreeze = freezeRouteRefresh();
40
+ if (!hardRefresh) {
41
+ // standard setting is to just perform an inject
42
+ const meta = JSON.parse(data);
43
+ const name = meta.name;
51
44
 
52
- // tear down pilet
53
- injectPilet({ name } as any);
45
+ // like a debounce; only one change of the current pilet should be actively processed
46
+ clearTimeout(timeoutCache[name]);
54
47
 
55
- // load and evaluate pilet
56
- loadPilet(meta).then((pilet) => {
57
- try {
58
- if (isfunc(injectPilet)) {
59
- injectPilet(pilet);
60
- }
48
+ // some bundlers may have fired before writing to the disk
49
+ // so we give them a bit of time before actually loading the pilet
50
+ timeoutCache[name] = setTimeout(() => {
51
+ // we should make sure to only refresh the page / router if pilets have been loaded
52
+ const unfreeze = freezeRouteRefresh();
61
53
 
62
- // setup actual pilet
63
- setupPilet(pilet, createApi);
54
+ // tear down pilet
55
+ injectPilet({ name } as any);
64
56
 
65
- // disable route cache, should be zero again and lead to route refresh
66
- unfreeze();
67
- } catch (error) {
68
- console.error(error);
57
+ // load and evaluate pilet
58
+ loadPilet(meta).then((pilet) => {
59
+ try {
60
+ if (isfunc(injectPilet)) {
61
+ injectPilet(pilet);
69
62
  }
70
- });
71
- }, timeout);
72
- } else {
73
- location.reload();
74
- }
75
- };
76
63
 
77
- return promise
78
- .catch((err) => {
79
- console.error(`Requesting the pilets failed. We'll continue loading without pilets (DEBUG only).`, err);
80
- return [];
81
- })
82
- .then((pilets) =>
83
- appendix.then((debugPilets) => {
84
- const debugPiletNames = debugPilets.map((m) => m.name);
85
- const feedPilets = pilets.filter((m) => !debugPiletNames.includes(m.name));
86
- return [...feedPilets, ...debugPilets];
87
- }),
88
- );
89
- },
90
- });
64
+ // setup actual pilet
65
+ setupPilet(pilet, createApi);
66
+
67
+ // disable route cache, should be zero again and lead to route refresh
68
+ unfreeze();
69
+ } catch (error) {
70
+ console.error(error);
71
+ }
72
+ });
73
+ }, timeout);
74
+ } else {
75
+ location.reload();
76
+ }
77
+ };
78
+
79
+ return promise
80
+ .catch((err) => {
81
+ console.error(`Requesting the pilets failed. We'll continue loading without pilets (DEBUG only).`, err);
82
+ return [];
83
+ })
84
+ .then((pilets) =>
85
+ appendix.then((debugPilets) => {
86
+ const debugPiletNames = debugPilets.map((m) => m.name);
87
+ const feedPilets = pilets.filter((m) => !debugPiletNames.includes(m.name));
88
+ return [...feedPilets, ...debugPilets];
89
+ }),
90
+ );
91
+ };
91
92
  }
package/src/types.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type { FC } from 'react';
2
- import type { Pilet, PiletApiCreator, PiletLoader, PiletMetadata, PiletRequester } from 'piral-base';
2
+ import type { Pilet, PiletApiCreator, PiletLoader, PiletMetadata } from 'piral-base';
3
3
 
4
4
  export interface EmulatorConnectorOptions {
5
5
  createApi: PiletApiCreator;
6
6
  loadPilet: PiletLoader;
7
7
  injectPilet?(pilet: Pilet): void;
8
8
  piletApiFallback?: string;
9
- integrate(components: EmulatorComponents): void;
9
+ integrate?(components: EmulatorComponents): void;
10
10
  }
11
11
 
12
12
  export interface ChangeSet {
@@ -19,7 +19,6 @@ export interface ChangeSet {
19
19
 
20
20
  export interface EmulatorComponents {
21
21
  components: Record<string, FC>;
22
- requester: PiletRequester;
23
22
  }
24
23
 
25
24
  export interface DebugComponents {