@akc42/app-utils 4.0.3 → 4.1.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/README.md +12 -0
- package/config.js +37 -0
- package/debug.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -251,3 +251,15 @@ class `LocationAltered` can generate it for you, so to change the location do:-
|
|
|
251
251
|
history.pushState({}, null, '/user/23');
|
|
252
252
|
window.dispatchEvent(new LocationAltered());
|
|
253
253
|
```
|
|
254
|
+
# config
|
|
255
|
+
|
|
256
|
+
Newly added in release 4.1.0, this function is used for getting the client config from the server
|
|
257
|
+
|
|
258
|
+
The default export, normally named config (ie the client does `import config from @akc42/app-utils/config.js`) and allows the normal await mechanisms in `import` to
|
|
259
|
+
allow this module to make an get request to the server of `/api/config` and for the server to return it. The `config` variable then holds (without any further waiting)
|
|
260
|
+
the client config object returned by the server.
|
|
261
|
+
|
|
262
|
+
Two non default async exports are also provided. `setConfig` called with no parameters will read the config from the server, called with a promise as a parameter it expects
|
|
263
|
+
that promise to be resolved with a config (useful in testing). The other async function is `reReadConfig` with essentially causes the config to be reRead, but does also returns a promise resolving to the config.
|
|
264
|
+
|
|
265
|
+
|
package/config.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@licence
|
|
3
|
+
Copyright (c) 2023 Alan Chandler, all rights reserved
|
|
4
|
+
|
|
5
|
+
This file is part of @akc42/app-utils.
|
|
6
|
+
|
|
7
|
+
@akc42/app-utils is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
@akc42/app-utils is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with @akc42/app-utils. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
let config = fetch('/api/config').then(response => response.json());
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export function setConfig(configPromise) {
|
|
25
|
+
//set config of (configPromise Undefined, re-read from server)
|
|
26
|
+
if (typeof configPromise === 'undefined') {
|
|
27
|
+
config = fetch('/api/config').then(response => response.json());
|
|
28
|
+
} else {
|
|
29
|
+
config = configPromise;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function reReadConfig() {
|
|
33
|
+
setConfig();//cause the reread to start
|
|
34
|
+
return await config;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default await config;
|
package/debug.js
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
debugDump - perform a dump to the server (and and a clearing out of the buffered info) of the debug calls made to date
|
|
64
64
|
|
|
65
65
|
*/
|
|
66
|
-
|
|
66
|
+
import config from './config.js';
|
|
67
67
|
const BUFFER_SIZE = 50;
|
|
68
68
|
const KEY_TOPIC = 'key'; //topic name which will get kept from a full resource buffer when we empty it.
|
|
69
69
|
let buffer = []; //buffer of up to 50 topic/message pairs to allow us to hold some if resource buffer becomes full;
|
|
@@ -137,7 +137,7 @@ function Debug(t) {
|
|
|
137
137
|
}, '');
|
|
138
138
|
if (initialised) performance.mark(this.topic, { detail: message }); //save our message locally regardless of if enabled
|
|
139
139
|
let enabled = false;
|
|
140
|
-
const debugConf =
|
|
140
|
+
const debugConf = config.debug;
|
|
141
141
|
if (debugConf) {
|
|
142
142
|
const topics = debugConf.split(':');
|
|
143
143
|
if (topics.includes(this.topic)) enabled = true;
|