@akc42/app-utils 3.1.5 → 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.
Files changed (3) hide show
  1. package/README.md +3 -5
  2. package/debug.js +11 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -134,11 +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**: the debug function checks with the server (via a debugconf api call)
138
- to see if the topic is enabled. This is then cached for a minute, so any
139
- calls around the same time will use the reply. This allows the server to
140
- change what topics are available and for the client side to quickly find if it
141
- should now start sending message
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.
142
140
 
143
141
  # dom-host
144
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
- import api from './post-api.js';
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
-
68
68
  if (topicMap.has(tl) ) {
69
69
  const topic = topicMap.get(tl);
70
70
  return topic.debug;
@@ -73,19 +73,21 @@ function Debug (t) {
73
73
  const topicHandler = {
74
74
  topic: tl,
75
75
  timestamp: new Date().getTime(),
76
- expires: 0, //when our knowledge of enabled expires
76
+ defined: false, //has the config been defined yet
77
77
  enabled: false, //is this topic enabled
78
78
  debug: async function (...args) {
79
79
  //do time calc before potential delay to see if we are enabled
80
80
  const now = new Date().getTime();
81
81
  const gap = now - this.timestamp;
82
82
  this.timestamp = now;
83
- if (now > this.expires) {
84
- //do this first so following requests don't try to find out again whilst I am checking, wasting calls
85
- this.expires = now + 60000;
86
- //expired so find out if topic is enabled
87
- this.enabled = await api(`debugconf/${this.topic}`);
88
-
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;
90
+ }
89
91
  }
90
92
  if (this.enabled) {
91
93
  const message = args.reduce((cum, arg) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akc42/app-utils",
3
- "version": "3.1.5",
3
+ "version": "3.2.0",
4
4
  "description": "General Utilities for SPAs",
5
5
  "exports": {
6
6
  ".": "./*.js"