@base-framework/base 3.8.3 → 3.9.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.
@@ -7,11 +7,29 @@
7
7
  * @class
8
8
  */
9
9
  export class DataPubSub {
10
+ /**
11
+ * This will create a data pub sub.
12
+ *
13
+ * @constructor
14
+ * @param {boolean} [indexPrefixes=false] Maintain an index of
15
+ * subscribed messages grouped by their `prefix:` segment. Used by
16
+ * the data binder so deep data can publish only to subscribed
17
+ * paths instead of walking every node of a value.
18
+ */
19
+ constructor(indexPrefixes?: boolean);
10
20
  /**
11
21
  * @type {Map} callBacks
12
22
  * @protected
13
23
  */
14
24
  protected callBacks: Map<any, any>;
25
+ /**
26
+ * Index of subscribed messages keyed by message prefix
27
+ * (substring through the first ':'). Null when disabled.
28
+ *
29
+ * @type {Map<string, Set<string>>|null}
30
+ * @protected
31
+ */
32
+ protected prefixIndex: Map<string, Set<string>> | null;
15
33
  /**
16
34
  * Queue for batching publish calls
17
35
  * @type {Map<string, Array>}
@@ -81,19 +99,55 @@ export class DataPubSub {
81
99
  /**
82
100
  * This will add a subscriber.
83
101
  *
102
+ * Tokens are numbers — string conversion was allocating a new
103
+ * string per watcher during page builds. Tokens are opaque to
104
+ * callers and only round-trip back into off().
105
+ *
84
106
  * @param {string} msg
85
107
  * @param {function} callBack
86
- * @returns {string} The subscriber token.
108
+ * @returns {number} The subscriber token.
109
+ */
110
+ on(msg: string, callBack: Function): number;
111
+ /**
112
+ * This will add a message to the prefix index.
113
+ *
114
+ * @protected
115
+ * @param {string} msg
116
+ * @returns {void}
117
+ */
118
+ protected _indexMessage(msg: string): void;
119
+ /**
120
+ * This will remove a message from the prefix index.
121
+ *
122
+ * @protected
123
+ * @param {string} msg
124
+ * @returns {void}
125
+ */
126
+ protected _unindexMessage(msg: string): void;
127
+ /**
128
+ * This will get the subscribed messages for a prefix
129
+ * (e.g. 'dt-3:'). Returns null when prefix indexing is
130
+ * disabled or no messages are subscribed.
131
+ *
132
+ * @param {string} prefix
133
+ * @returns {Set<string>|null}
134
+ */
135
+ getPrefixMessages(prefix: string): Set<string> | null;
136
+ /**
137
+ * This will get the subscribed message keys. Used by deep data
138
+ * to publish only to subscribed paths.
139
+ *
140
+ * @returns {IterableIterator<string>}
87
141
  */
88
- on(msg: string, callBack: Function): string;
142
+ getMessages(): IterableIterator<string>;
89
143
  /**
90
144
  * This will remove a subscriber.
91
145
  *
92
146
  * @param {string} msg
93
- * @param {string} token
147
+ * @param {number} token
94
148
  * @returns {void}
95
149
  */
96
- off(msg: string, token: string): void;
150
+ off(msg: string, token: number): void;
97
151
  /**
98
152
  * This will delete a message.
99
153
  *
@@ -70,9 +70,9 @@ export class StateTracker {
70
70
  * @param {string} targetId
71
71
  * @param {string} action
72
72
  * @param {function} callBack
73
- * @returns {?string}
73
+ * @returns {?number}
74
74
  */
75
- static on(targetId: string, action: string, callBack: Function): string | null;
75
+ static on(targetId: string, action: string, callBack: Function): number | null;
76
76
  /**
77
77
  * This will remove a subscriber from an action.
78
78
  *
@@ -29,9 +29,9 @@ export class State extends SimpleData {
29
29
  * whole action is removed.
30
30
  *
31
31
  * @param {string} action
32
- * @param {string} [token]
32
+ * @param {number} [token]
33
33
  * @returns {this}
34
34
  */
35
- removeAction(action: string, token?: string): this;
35
+ removeAction(action: string, token?: number): this;
36
36
  }
37
37
  import { SimpleData } from '../data/data.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base-framework/base",
3
- "version": "3.8.3",
3
+ "version": "3.9.0",
4
4
  "description": "This is a javascript framework.",
5
5
  "main": "./dist/base.js",
6
6
  "type": "module",