@akc42/app-utils 4.0.2 → 4.1.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 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/location.js CHANGED
@@ -79,7 +79,7 @@ function routeChanged(e) {
79
79
  let newPath = route.path;
80
80
  if(e.detail.path !== undefined) {
81
81
  if (Number.isInteger(e.detail.segment)) {
82
- debug('route change called path', e.detail.path, 'segments', d.detail.segment, 'current path', route.path )
82
+ debug('route change called path', e.detail.path, 'segments', e.detail.segment, 'current path', route.path )
83
83
  let segments = route.path.split('/');
84
84
  if (segments[0] === '') segments.shift(); //loose leeding
85
85
  if(segments.length < e.detail.segment) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akc42/app-utils",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "description": "General Utilities for SPAs",
5
5
  "exports": {
6
6
  ".": "./*.js"