@akc42/app-utils 3.1.2 → 3.2.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.
- package/README.md +3 -7
- package/debug.js +29 -21
- package/package.json +1 -1
- package/submit-function.js +8 -5
package/README.md
CHANGED
|
@@ -134,13 +134,9 @@ The purpose of this module is to provide a debugable capability which can be
|
|
|
134
134
|
config-promise) is set to a string which is a comma separated list of topics
|
|
135
135
|
and that list has the topic for this debug call in it.
|
|
136
136
|
|
|
137
|
-
**Note**:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
function to use the `mockConfig` call to replace the promise with one which
|
|
141
|
-
contained a different list of topics. `debug` (the function returned by the
|
|
142
|
-
call to `Debug('topic')`) checks the list of topics on every call so would
|
|
143
|
-
dynamically pick up the changes
|
|
137
|
+
**Note**: the debug function checks with the sessionStorage.getItem('debug) (via an await for the Config Promise)
|
|
138
|
+
to see if the topic is enabled (assumes the result is a ':' separated string of topics). This allows the server to
|
|
139
|
+
change what topics are available via the config api call.
|
|
144
140
|
|
|
145
141
|
# dom-host
|
|
146
142
|
|
package/debug.js
CHANGED
|
@@ -53,10 +53,11 @@
|
|
|
53
53
|
would dynamically pick up the changes
|
|
54
54
|
|
|
55
55
|
*/
|
|
56
|
+
import config from './config-promise.js';
|
|
56
57
|
|
|
57
58
|
const topicMap = new Map();
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
|
|
60
61
|
|
|
61
62
|
function Debug (t) {
|
|
62
63
|
if (typeof t !== 'string' || t.length === 0 || !/^[a-zA-Z]+$/.test(t)) {
|
|
@@ -64,7 +65,6 @@ function Debug (t) {
|
|
|
64
65
|
throw new Error('Invalid Debug Topic');
|
|
65
66
|
}
|
|
66
67
|
const tl = t.toLowerCase();
|
|
67
|
-
let timestamp = new Date().getTime();
|
|
68
68
|
if (topicMap.has(tl) ) {
|
|
69
69
|
const topic = topicMap.get(tl);
|
|
70
70
|
return topic.debug;
|
|
@@ -73,26 +73,34 @@ function Debug (t) {
|
|
|
73
73
|
const topicHandler = {
|
|
74
74
|
topic: tl,
|
|
75
75
|
timestamp: new Date().getTime(),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
navigator.sendBeacon(`/api/debuglog/${this.topic}`, blob);
|
|
76
|
+
defined: false, //has the config been defined yet
|
|
77
|
+
enabled: false, //is this topic enabled
|
|
78
|
+
debug: async function (...args) {
|
|
79
|
+
//do time calc before potential delay to see if we are enabled
|
|
80
|
+
const now = new Date().getTime();
|
|
81
|
+
const gap = now - this.timestamp;
|
|
82
|
+
this.timestamp = now;
|
|
83
|
+
if (!this.defined) {
|
|
84
|
+
await config();
|
|
85
|
+
this.defined = true;
|
|
86
|
+
const debugConf = sessionStorage.getItem('debug');
|
|
87
|
+
if (debugConf) {
|
|
88
|
+
const topics = debugConf.split(':');
|
|
89
|
+
if (topics.includes(this.topic)) this.enabled = true;
|
|
92
90
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
}
|
|
92
|
+
if (this.enabled) {
|
|
93
|
+
const message = args.reduce((cum, arg) => {
|
|
94
|
+
return `${cum} ${arg}`.trim();
|
|
95
|
+
}, '');
|
|
96
|
+
console.log(`+${gap}ms`, this.topic, message);
|
|
97
|
+
const blob = new Blob([JSON.stringify({
|
|
98
|
+
message: message,
|
|
99
|
+
gap: gap
|
|
100
|
+
})], { type: 'application/json' })
|
|
101
|
+
|
|
102
|
+
navigator.sendBeacon(`/api/debuglog/${this.topic}`, blob);
|
|
103
|
+
}
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
topicHandler.debug = topicHandler.debug.bind(topicHandler);
|
package/package.json
CHANGED
package/submit-function.js
CHANGED
|
@@ -75,11 +75,14 @@ export default function submit(e) {
|
|
|
75
75
|
}
|
|
76
76
|
const params = {};
|
|
77
77
|
if (checkLevel(target, params)) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
document.body.dispatchEvent(new CustomEvent('wait-request', {detail:
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
const action = target.getAttribute('action')
|
|
79
|
+
if (target.dispatchEvent(new CustomEvent('form-submitting', { cancelable:true, composed: true, bubbles: true, detail: params}))) {
|
|
80
|
+
document.body.dispatchEvent(new CustomEvent('wait-request', {detail: true }));
|
|
81
|
+
api(action, params).then(response => {
|
|
82
|
+
document.body.dispatchEvent(new CustomEvent('wait-request', {detail: false }));
|
|
83
|
+
target.dispatchEvent(new CustomEvent('form-response', { composed: true, bubbles: true, detail: response }));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
83
86
|
return params;
|
|
84
87
|
} else {
|
|
85
88
|
target.dispatchEvent(new CustomEvent('form-response', { composed: true, bubbles: true, detail: null }));
|