@trackunit/iris-app-runtime-core 1.15.17-alpha-71bd6bc448a.0 → 1.15.17
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 +26 -80
- package/index.esm.js +26 -80
- package/package.json +2 -2
- package/src/HostConnector.d.ts +3 -6
package/index.cjs.js
CHANGED
|
@@ -3,98 +3,44 @@
|
|
|
3
3
|
var irisAppRuntimeCoreApi = require('@trackunit/iris-app-runtime-core-api');
|
|
4
4
|
var penpal = require('penpal');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* intersection behavior when indexing by `keyof ChildConnectorApi`. Type safety
|
|
9
|
-
* is enforced at the `setupHostConnector` boundary where the input still
|
|
10
|
-
* satisfies `Partial<ChildConnectorApi>`.
|
|
11
|
-
*/
|
|
12
|
-
const subscribers = {};
|
|
13
|
-
const childApiMethodNames = [
|
|
14
|
-
"onFilterBarValuesChanged",
|
|
15
|
-
"onTokenChanged",
|
|
16
|
-
"onAssetSortingStateChanged",
|
|
17
|
-
"onAssetsFilterBarValuesChanged",
|
|
18
|
-
"onCustomersFilterBarValuesChanged",
|
|
19
|
-
"onSitesFilterBarValuesChanged",
|
|
20
|
-
"onTablePersistenceStateChanged",
|
|
21
|
-
"onTimeRangeChanged",
|
|
22
|
-
"onWidgetPollIntervalChanged",
|
|
23
|
-
];
|
|
24
|
-
const makeDispatcher = (methodName) => (...args) => {
|
|
25
|
-
const handlers = subscribers[methodName];
|
|
26
|
-
if (!handlers || handlers.length === 0) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
for (const handler of [...handlers]) {
|
|
30
|
-
try {
|
|
31
|
-
handler(...args);
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
// eslint-disable-next-line no-console
|
|
35
|
-
console.error(`[iris-app-runtime-core] subscriber for "${methodName}" threw`, error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
6
|
+
const doNothingByDefault = () => {
|
|
7
|
+
// do nothing by default
|
|
38
8
|
};
|
|
39
|
-
const dispatchTable = childApiMethodNames.reduce((table, name) => {
|
|
40
|
-
table[name] = makeDispatcher(name);
|
|
41
|
-
return table;
|
|
42
|
-
}, {});
|
|
43
|
-
const singletonConnection = penpal.connectToParent({
|
|
44
|
-
methods: dispatchTable,
|
|
45
|
-
});
|
|
46
|
-
singletonConnection.promise.catch(error => {
|
|
47
|
-
// TODO consider how to handle this catch
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.log(error);
|
|
50
|
-
});
|
|
51
9
|
/**
|
|
52
|
-
*
|
|
53
|
-
* shared dispatch table; unlike the previous implementation this does NOT open
|
|
54
|
-
* a new Penpal connection. The returned `destroy()` unregisters only the
|
|
55
|
-
* handlers this call installed and never tears down the shared connection.
|
|
10
|
+
* Setup using the subscribedMethods to subscribe to events from the host.
|
|
56
11
|
*
|
|
57
|
-
* @param subscribedMethods
|
|
58
|
-
* @returns {Connection<HostConnectorApi>}
|
|
12
|
+
* @param subscribedMethods the methods to subscribe to
|
|
13
|
+
* @returns { Connection<HostConnectorApi> } the connection to the host
|
|
59
14
|
*/
|
|
60
15
|
const setupHostConnector = (subscribedMethods) => {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const current = subscribers[key];
|
|
73
|
-
if (!current) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const index = current.indexOf(erased);
|
|
77
|
-
if (index >= 0) {
|
|
78
|
-
current.splice(index, 1);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
promise: singletonConnection.promise,
|
|
84
|
-
destroy: () => {
|
|
85
|
-
for (const unregister of unregisterCallbacks) {
|
|
86
|
-
unregister();
|
|
87
|
-
}
|
|
88
|
-
},
|
|
16
|
+
const methods = {
|
|
17
|
+
onFilterBarValuesChanged: doNothingByDefault,
|
|
18
|
+
onTokenChanged: doNothingByDefault,
|
|
19
|
+
onAssetSortingStateChanged: doNothingByDefault,
|
|
20
|
+
onAssetsFilterBarValuesChanged: doNothingByDefault,
|
|
21
|
+
onCustomersFilterBarValuesChanged: doNothingByDefault,
|
|
22
|
+
onSitesFilterBarValuesChanged: doNothingByDefault,
|
|
23
|
+
onTablePersistenceStateChanged: doNothingByDefault,
|
|
24
|
+
onTimeRangeChanged: doNothingByDefault,
|
|
25
|
+
onWidgetPollIntervalChanged: doNothingByDefault,
|
|
26
|
+
...subscribedMethods,
|
|
89
27
|
};
|
|
90
|
-
};
|
|
28
|
+
const connection = penpal.connectToParent({ methods });
|
|
29
|
+
connection.promise.catch(err => {
|
|
30
|
+
// TODO consider how to handle this catch
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log(err);
|
|
33
|
+
});
|
|
34
|
+
return connection;
|
|
35
|
+
};
|
|
36
|
+
const hostConnector = setupHostConnector({});
|
|
91
37
|
/**
|
|
92
38
|
* Gets the host connector.
|
|
93
39
|
*
|
|
94
40
|
* @returns { Promise<Connection<HostConnectorApi>> } the connection to the host
|
|
95
41
|
*/
|
|
96
42
|
const getHostConnector = () => {
|
|
97
|
-
return
|
|
43
|
+
return hostConnector.promise;
|
|
98
44
|
};
|
|
99
45
|
|
|
100
46
|
/**
|
package/index.esm.js
CHANGED
|
@@ -1,98 +1,44 @@
|
|
|
1
1
|
export * from '@trackunit/iris-app-runtime-core-api';
|
|
2
2
|
import { connectToParent } from 'penpal';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* intersection behavior when indexing by `keyof ChildConnectorApi`. Type safety
|
|
7
|
-
* is enforced at the `setupHostConnector` boundary where the input still
|
|
8
|
-
* satisfies `Partial<ChildConnectorApi>`.
|
|
9
|
-
*/
|
|
10
|
-
const subscribers = {};
|
|
11
|
-
const childApiMethodNames = [
|
|
12
|
-
"onFilterBarValuesChanged",
|
|
13
|
-
"onTokenChanged",
|
|
14
|
-
"onAssetSortingStateChanged",
|
|
15
|
-
"onAssetsFilterBarValuesChanged",
|
|
16
|
-
"onCustomersFilterBarValuesChanged",
|
|
17
|
-
"onSitesFilterBarValuesChanged",
|
|
18
|
-
"onTablePersistenceStateChanged",
|
|
19
|
-
"onTimeRangeChanged",
|
|
20
|
-
"onWidgetPollIntervalChanged",
|
|
21
|
-
];
|
|
22
|
-
const makeDispatcher = (methodName) => (...args) => {
|
|
23
|
-
const handlers = subscribers[methodName];
|
|
24
|
-
if (!handlers || handlers.length === 0) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
for (const handler of [...handlers]) {
|
|
28
|
-
try {
|
|
29
|
-
handler(...args);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
// eslint-disable-next-line no-console
|
|
33
|
-
console.error(`[iris-app-runtime-core] subscriber for "${methodName}" threw`, error);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
4
|
+
const doNothingByDefault = () => {
|
|
5
|
+
// do nothing by default
|
|
36
6
|
};
|
|
37
|
-
const dispatchTable = childApiMethodNames.reduce((table, name) => {
|
|
38
|
-
table[name] = makeDispatcher(name);
|
|
39
|
-
return table;
|
|
40
|
-
}, {});
|
|
41
|
-
const singletonConnection = connectToParent({
|
|
42
|
-
methods: dispatchTable,
|
|
43
|
-
});
|
|
44
|
-
singletonConnection.promise.catch(error => {
|
|
45
|
-
// TODO consider how to handle this catch
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
47
|
-
console.log(error);
|
|
48
|
-
});
|
|
49
7
|
/**
|
|
50
|
-
*
|
|
51
|
-
* shared dispatch table; unlike the previous implementation this does NOT open
|
|
52
|
-
* a new Penpal connection. The returned `destroy()` unregisters only the
|
|
53
|
-
* handlers this call installed and never tears down the shared connection.
|
|
8
|
+
* Setup using the subscribedMethods to subscribe to events from the host.
|
|
54
9
|
*
|
|
55
|
-
* @param subscribedMethods
|
|
56
|
-
* @returns {Connection<HostConnectorApi>}
|
|
10
|
+
* @param subscribedMethods the methods to subscribe to
|
|
11
|
+
* @returns { Connection<HostConnectorApi> } the connection to the host
|
|
57
12
|
*/
|
|
58
13
|
const setupHostConnector = (subscribedMethods) => {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const current = subscribers[key];
|
|
71
|
-
if (!current) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const index = current.indexOf(erased);
|
|
75
|
-
if (index >= 0) {
|
|
76
|
-
current.splice(index, 1);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
promise: singletonConnection.promise,
|
|
82
|
-
destroy: () => {
|
|
83
|
-
for (const unregister of unregisterCallbacks) {
|
|
84
|
-
unregister();
|
|
85
|
-
}
|
|
86
|
-
},
|
|
14
|
+
const methods = {
|
|
15
|
+
onFilterBarValuesChanged: doNothingByDefault,
|
|
16
|
+
onTokenChanged: doNothingByDefault,
|
|
17
|
+
onAssetSortingStateChanged: doNothingByDefault,
|
|
18
|
+
onAssetsFilterBarValuesChanged: doNothingByDefault,
|
|
19
|
+
onCustomersFilterBarValuesChanged: doNothingByDefault,
|
|
20
|
+
onSitesFilterBarValuesChanged: doNothingByDefault,
|
|
21
|
+
onTablePersistenceStateChanged: doNothingByDefault,
|
|
22
|
+
onTimeRangeChanged: doNothingByDefault,
|
|
23
|
+
onWidgetPollIntervalChanged: doNothingByDefault,
|
|
24
|
+
...subscribedMethods,
|
|
87
25
|
};
|
|
88
|
-
};
|
|
26
|
+
const connection = connectToParent({ methods });
|
|
27
|
+
connection.promise.catch(err => {
|
|
28
|
+
// TODO consider how to handle this catch
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log(err);
|
|
31
|
+
});
|
|
32
|
+
return connection;
|
|
33
|
+
};
|
|
34
|
+
const hostConnector = setupHostConnector({});
|
|
89
35
|
/**
|
|
90
36
|
* Gets the host connector.
|
|
91
37
|
*
|
|
92
38
|
* @returns { Promise<Connection<HostConnectorApi>> } the connection to the host
|
|
93
39
|
*/
|
|
94
40
|
const getHostConnector = () => {
|
|
95
|
-
return
|
|
41
|
+
return hostConnector.promise;
|
|
96
42
|
};
|
|
97
43
|
|
|
98
44
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/iris-app-runtime-core",
|
|
3
|
-
"version": "1.15.17
|
|
3
|
+
"version": "1.15.17",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"penpal": "^6.2.2",
|
|
11
|
-
"@trackunit/iris-app-runtime-core-api": "1.14.17
|
|
11
|
+
"@trackunit/iris-app-runtime-core-api": "1.14.17"
|
|
12
12
|
},
|
|
13
13
|
"module": "./index.esm.js",
|
|
14
14
|
"main": "./index.cjs.js",
|
package/src/HostConnector.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { ChildConnectorApi, HostConnectorApi } from "@trackunit/iris-app-runtime-core-api";
|
|
2
2
|
import { AsyncMethodReturns, Connection, Methods } from "penpal";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* shared dispatch table; unlike the previous implementation this does NOT open
|
|
6
|
-
* a new Penpal connection. The returned `destroy()` unregisters only the
|
|
7
|
-
* handlers this call installed and never tears down the shared connection.
|
|
4
|
+
* Setup using the subscribedMethods to subscribe to events from the host.
|
|
8
5
|
*
|
|
9
|
-
* @param subscribedMethods
|
|
10
|
-
* @returns {Connection<HostConnectorApi>}
|
|
6
|
+
* @param subscribedMethods the methods to subscribe to
|
|
7
|
+
* @returns { Connection<HostConnectorApi> } the connection to the host
|
|
11
8
|
*/
|
|
12
9
|
export declare const setupHostConnector: (subscribedMethods: Partial<ChildConnectorApi> & Methods) => Connection<HostConnectorApi>;
|
|
13
10
|
/**
|