@soundworks/core 5.6.0 → 5.7.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.
@@ -24,7 +24,7 @@ import {
24
24
  * @private
25
25
  */
26
26
  function whiteListFilterUpdates(updates, whiteList) {
27
- if (whiteList === null) {
27
+ if (!Array.isArray(whiteList)) {
28
28
  return updates;
29
29
  }
30
30
 
@@ -44,7 +44,7 @@ function whiteListFilterUpdates(updates, whiteList) {
44
44
  * @private
45
45
  */
46
46
  function blackListFilterUpdates(updates, blackList) {
47
- if (blackList === null) {
47
+ if (!Array.isArray(blackList)) {
48
48
  return updates;
49
49
  }
50
50
  // create a shallow copy so we can have multiple filters applied on same source
@@ -59,6 +59,22 @@ function blackListFilterUpdates(updates, blackList) {
59
59
  return filtered;
60
60
  }
61
61
 
62
+ function applyFilters(updates, options) {
63
+ if (options === null) {
64
+ return updates;
65
+ }
66
+
67
+ const { whiteList, blackList } = options;
68
+ // precedence to white list
69
+ if (Array.isArray(whiteList)) {
70
+ updates = whiteListFilterUpdates(updates, whiteList);
71
+ } else if (Array.isArray(blackList)) {
72
+ updates = blackListFilterUpdates(updates, blackList);
73
+ }
74
+
75
+ return updates;
76
+ }
77
+
62
78
  export const kSharedStatePrivateAttachClient = Symbol('soundworks:shared-state-private-attach-client');
63
79
  export const kSharedStatePrivateDetachClient = Symbol('soundworks:shared-state-private-detach-client');
64
80
  export const kSharedStatePrivateGetValues = Symbol('soundworks:shared-state-private-get-values');
@@ -74,8 +90,7 @@ class SharedStatePrivate {
74
90
  #className = null;
75
91
  #manager = null;
76
92
  #parameters = null;
77
- #creatorId = null;
78
- #creatorInstanceId = null;
93
+ #ownerId = null;
79
94
  #attachedClients = new Map();
80
95
 
81
96
  constructor(manager, className, classDefinition, id, initValues = {}) {
@@ -94,12 +109,8 @@ class SharedStatePrivate {
94
109
  return this.#className;
95
110
  }
96
111
 
97
- get creatorId() {
98
- return this.#creatorId;
99
- }
100
-
101
- get creatorInstanceId() {
102
- return this.#creatorInstanceId;
112
+ get ownerId() {
113
+ return this.#ownerId;
103
114
  }
104
115
 
105
116
  get attachedClients() {
@@ -114,21 +125,53 @@ class SharedStatePrivate {
114
125
  return this.#parameters.getValues();
115
126
  }
116
127
 
117
- [kSharedStatePrivateAttachClient](instanceId, client, isOwner, filter) {
118
- const clientInfos = { client, isOwner, filter };
128
+ [kSharedStatePrivateAttachClient](instanceId, client, isOwner, options) {
129
+ if (isOwner) {
130
+ this.#ownerId = client.id;
131
+ }
132
+
133
+ const clientInfos = { client, isOwner, options };
119
134
  this.#attachedClients.set(instanceId, clientInfos);
120
135
 
136
+ client.transport.addListener(`${UPDATE_REQUEST}-${this.id}-${instanceId}`, this.#onUpdateRequest(instanceId, client));
137
+
121
138
  if (isOwner) {
122
- this.#creatorId = client.id;
123
- this.#creatorInstanceId = instanceId;
139
+ client.transport.addListener(`${DELETE_REQUEST}-${this.id}-${instanceId}`, this.#onDeleteRequest);
140
+ } else {
141
+ client.transport.addListener(`${DETACH_REQUEST}-${this.id}-${instanceId}`, this.#onDetachRequest(instanceId, client));
142
+ this.#updateHasSiblings();
124
143
  }
144
+ }
145
+
146
+ [kSharedStatePrivateDetachClient](instanceId, client) {
147
+ this.#attachedClients.delete(instanceId);
148
+
149
+ client.transport.removeAllListeners(`${UPDATE_REQUEST}-${this.id}-${instanceId}`);
150
+ client.transport.removeAllListeners(`${DELETE_REQUEST}-${this.id}-${instanceId}`);
151
+ client.transport.removeAllListeners(`${DETACH_REQUEST}-${this.id}-${instanceId}`);
152
+
153
+ this.#updateHasSiblings();
154
+ }
155
+
156
+ /**
157
+ * Update hasSiblings property on owner
158
+ */
159
+ #updateHasSiblings() {
160
+ for (let [instanceId, clientInfos] of this.attachedClients) {
161
+ const { client, isOwner } = clientInfos;
125
162
 
126
- // attach client listeners
127
- client.transport.addListener(`${UPDATE_REQUEST}-${this.id}-${instanceId}`, async (reqId, updates) => {
128
- // apply registered hooks
163
+ if (isOwner) {
164
+ const hasSiblings = this.attachedClients.size > 1;
165
+ client.transport.emit(`${HAS_SIBLINGS_NOTIFICATION}-${this.id}-${instanceId}`, hasSiblings);
166
+ }
167
+ }
168
+ }
169
+
170
+ #onUpdateRequest = (instanceId, client) => {
171
+ return async (reqId, updates) => {
129
172
  const hooks = this.#manager[kServerStateManagerGetUpdateHooks](this.className);
130
173
  const values = this.#parameters.getValues();
131
- // make sur we don't propagate back to requester param that are marked as `acknowledge=false`
174
+ // Do not propagate back to the requester, params that are marked as `acknowledge=false`
132
175
  const acknowledgeFilter = this.#parameters.getParamListByDescriptor('acknowledge', false);
133
176
 
134
177
  let hookAborted = false;
@@ -186,8 +229,9 @@ class SharedStatePrivate {
186
229
  //
187
230
  // @note - instanceId correspond to unique remote state id
188
231
 
189
- // - Apply acknowledge filter on `acknowledgedUpdates`
190
- // - We don't need to apply the regular filter on update request, they are blocked client-side
232
+ // Apply acknowledge filter on `acknowledgedUpdates`
233
+ // Note that, We don't need to apply the whiteList / blackList filters
234
+ // for the requester, as they are blocked early on client-side
191
235
  const requesterFilteredUpdates = blackListFilterUpdates(acknowledgedUpdates, acknowledgeFilter);
192
236
 
193
237
  // propagate RESPONSE to the client that originates the request if not the server
@@ -204,11 +248,12 @@ class SharedStatePrivate {
204
248
 
205
249
  // propagate NOTIFICATION to all peer states except on server-side
206
250
  for (let [peerInstanceId, clientInfos] of this.#attachedClients) {
207
- const { client: peer, filter } = clientInfos;
251
+ const { client: peer, options } = clientInfos;
208
252
 
209
253
  if (instanceId !== peerInstanceId && peer.id !== -1) {
210
- const filteredUpdates = whiteListFilterUpdates(acknowledgedUpdates, filter);
211
- // propagate only if there something left after applying the white list filter
254
+ const filteredUpdates = applyFilters(acknowledgedUpdates, options);
255
+
256
+ // propagate only if there something left after applying the whiteList/blackList filters
212
257
  if (Object.keys(filteredUpdates).length > 0) {
213
258
  peer.transport.emit(
214
259
  `${UPDATE_NOTIFICATION}-${this.id}-${peerInstanceId}`,
@@ -232,11 +277,12 @@ class SharedStatePrivate {
232
277
 
233
278
  // propagate NOTIFICATION to all peer states on the server-side
234
279
  for (let [peerInstanceId, clientInfos] of this.#attachedClients) {
235
- const { client: peer, filter } = clientInfos;
280
+ const { client: peer, options } = clientInfos;
236
281
 
237
282
  if (instanceId !== peerInstanceId && peer.id === -1) {
238
- const filteredUpdates = whiteListFilterUpdates(acknowledgedUpdates, filter);
239
- // propagate only if there something left after applying the white list filter
283
+ const filteredUpdates = applyFilters(acknowledgedUpdates, options);
284
+
285
+ // propagate only if there something left after applying the whiteList/blackList filters
240
286
  if (Object.keys(filteredUpdates).length > 0) {
241
287
  peer.transport.emit(
242
288
  `${UPDATE_NOTIFICATION}-${this.id}-${peerInstanceId}`,
@@ -254,9 +300,9 @@ class SharedStatePrivate {
254
300
  client.transport.emit(`${UPDATE_ABORT}-${this.id}-${instanceId}`, reqId, requesterFilteredUpdates);
255
301
  }
256
302
  }
257
- } else {
258
- // @note - abort messages are only sent back to requester
259
- // explicitly aborted by hook (return `null`), send back current values to requester
303
+ } else { // hookAborted === true
304
+ // when explicitly aborted by a hook (return `null`), we only send
305
+ // back the current values to the requester
260
306
  const currentValues = {};
261
307
 
262
308
  for (let name in updates) {
@@ -268,64 +314,36 @@ class SharedStatePrivate {
268
314
  client.transport.emit(`${UPDATE_ABORT}-${this.id}-${instanceId}`, reqId, requesterFilteredUpdates);
269
315
  }
270
316
  }
271
- });
272
-
273
- if (isOwner) {
274
- // delete only if creator
275
- client.transport.addListener(`${DELETE_REQUEST}-${this.id}-${instanceId}`, async reqId => {
276
- // make sure hooks have been called when `delete()` fulfills
277
- await this.#manager[kServerStateManagerDeletePrivateState](this);
278
- // --------------------------------------------------------------------
279
- // WARNING - MAKE SURE WE DON'T HAVE PROBLEM W/ THAT
280
- // --------------------------------------------------------------------
281
- // @todo - propagate server-side last, because if a subscription function sends a
282
- // message to a client, network messages order are kept coherent
283
- // this._subscriptions.forEach(func => func(updated));
284
- for (let [instanceId, clientInfos] of this.#attachedClients) {
285
- const attached = clientInfos.client;
286
- this[kSharedStatePrivateDetachClient](instanceId, attached);
287
-
288
- if (instanceId === this.#creatorInstanceId) {
289
- attached.transport.emit(`${DELETE_RESPONSE}-${this.id}-${instanceId}`, reqId);
290
- } else {
291
- attached.transport.emit(`${DELETE_NOTIFICATION}-${this.id}-${instanceId}`);
292
- }
293
- }
294
- });
295
- } else {
296
- // detach only if not creator
297
- client.transport.addListener(`${DETACH_REQUEST}-${this.id}-${instanceId}`, (reqId) => {
298
- this[kSharedStatePrivateDetachClient](instanceId, client);
299
- client.transport.emit(`${DETACH_RESPONSE}-${this.id}-${instanceId}`, reqId);
300
- });
301
-
302
- this.#updateHasSiblings();
303
- }
304
- }
305
-
306
- [kSharedStatePrivateDetachClient](instanceId, client) {
307
- this.#attachedClients.delete(instanceId);
308
- // delete listeners
309
- client.transport.removeAllListeners(`${UPDATE_REQUEST}-${this.id}-${instanceId}`);
310
- client.transport.removeAllListeners(`${DELETE_REQUEST}-${this.id}-${instanceId}`);
311
- client.transport.removeAllListeners(`${DETACH_REQUEST}-${this.id}-${instanceId}`);
312
-
313
- this.#updateHasSiblings();
314
- }
315
-
316
- /**
317
- * Update hasSiblings property on owner
318
- */
319
- #updateHasSiblings() {
320
- for (let [instanceId, clientInfos] of this.attachedClients) {
317
+ };
318
+ };
319
+
320
+ #onDeleteRequest = async reqId => {
321
+ // make sure hooks have been called when `delete()` fulfills
322
+ await this.#manager[kServerStateManagerDeletePrivateState](this);
323
+ // --------------------------------------------------------------------
324
+ // WARNING - MAKE SURE WE DON'T HAVE PROBLEM W/ THAT
325
+ // --------------------------------------------------------------------
326
+ // @todo - propagate server-side last, because if a subscription function sends a
327
+ // message to a client, network messages order are kept coherent
328
+ // this._subscriptions.forEach(func => func(updated));
329
+ for (let [instanceId, clientInfos] of this.#attachedClients) {
321
330
  const { client, isOwner } = clientInfos;
331
+ this[kSharedStatePrivateDetachClient](instanceId, client);
322
332
 
323
333
  if (isOwner) {
324
- const hasSiblings = this.attachedClients.size > 1;
325
- client.transport.emit(`${HAS_SIBLINGS_NOTIFICATION}-${this.id}-${instanceId}`, hasSiblings);
334
+ client.transport.emit(`${DELETE_RESPONSE}-${this.id}-${instanceId}`, reqId);
335
+ } else {
336
+ client.transport.emit(`${DELETE_NOTIFICATION}-${this.id}-${instanceId}`);
326
337
  }
327
338
  }
328
- }
339
+ };
340
+
341
+ #onDetachRequest = (instanceId, client) => {
342
+ return reqId => {
343
+ this[kSharedStatePrivateDetachClient](instanceId, client);
344
+ client.transport.emit(`${DETACH_RESPONSE}-${this.id}-${instanceId}`, reqId);
345
+ };
346
+ };
329
347
  }
330
348
 
331
349
  export default SharedStatePrivate;
@@ -1,5 +1,6 @@
1
1
  export const kStateManagerInit: unique symbol;
2
2
  export const kStateManagerDeleteState: unique symbol;
3
+ export const kPendingSharedStateConstructionData: unique symbol;
3
4
  export const kStateManagerClient: unique symbol;
4
5
  export default BaseStateManager;
5
6
  /**
@@ -46,10 +47,6 @@ declare class BaseStateManager {
46
47
  * const classDescription = await client.stateManager.getClassDescription('my-class');
47
48
  */
48
49
  getClassDescription(className: SharedStateClassName): SharedStateClassDescription;
49
- /**
50
- * @deprecated Use {@link BaseStateManager#getClassDescription} instead.
51
- */
52
- getSchema(className: any): Promise<any>;
53
50
  /**
54
51
  * Create a {@link SharedState} instance from a registered class.
55
52
  *
@@ -90,26 +87,36 @@ declare class BaseStateManager {
90
87
  *
91
88
  * @overload
92
89
  * @param {SharedStateClassName} className - Name of the class.
93
- * @param {string[]} filter - List of parameters of interest
90
+ * @param {Object} [options={}]
91
+ * @param {string[]} [options.whiteList] - White list of parameter names to track (as precedence over `blackList`).
92
+ * @param {string[]} [options.blackList] - Black list of parameter names to ignore.
94
93
  * @returns {Promise<SharedState>}
95
94
  *
96
95
  * @example
97
96
  * const state = await client.stateManager.attach('my-class', ['some-param']);
98
97
  */
99
- attach(className: SharedStateClassName, filter: string[]): Promise<SharedState>;
98
+ attach(className: SharedStateClassName, options?: {
99
+ whiteList?: string[] | undefined;
100
+ blackList?: string[] | undefined;
101
+ } | undefined): Promise<SharedState>;
100
102
  /**
101
103
  * Attach to an existing {@link SharedState} instance.
102
104
  *
103
105
  * @overload
104
106
  * @param {SharedStateClassName} className - Name of the class.
105
107
  * @param {number} stateId - Id of the state
106
- * @param {string[]} filter - List of parameters of interest
108
+ * @param {object} [options={}]
109
+ * @param {string[]} [options.whiteList] - White list of parameter names to track (as precedence over `blackList`).
110
+ * @param {string[]} [options.blackList] - Black list of parameter names to ignore.
107
111
  * @returns {Promise<SharedState>}
108
112
  *
109
113
  * @example
110
114
  * const state = await client.stateManager.attach('my-class', stateId, ['some-param']);
111
115
  */
112
- attach(className: SharedStateClassName, stateId: number, filter: string[]): Promise<SharedState>;
116
+ attach(className: SharedStateClassName, stateId: number, options?: {
117
+ whiteList?: string[] | undefined;
118
+ blackList?: string[] | undefined;
119
+ } | undefined): Promise<SharedState>;
113
120
  /**
114
121
  * Observe all the {@link SharedState} instances that are created on the network.
115
122
  *
@@ -147,7 +154,7 @@ declare class BaseStateManager {
147
154
  * @param {stateManagerObserveCallback} callback - Function to execute when a
148
155
  * new {@link SharedState} is created on the network.
149
156
  * @param {object} options - Options.
150
- * @param {boolean} options.excludeLocal=false - If set to true, exclude states
157
+ * @param {boolean} [options.excludeLocal=false] - If set to true, exclude states
151
158
  * created by the same node from the collection.
152
159
  * @example
153
160
  * client.stateManager.observe(async (className, stateId) => {
@@ -157,7 +164,7 @@ declare class BaseStateManager {
157
164
  * }, { excludeLocal: true });
158
165
  */
159
166
  observe(callback: stateManagerObserveCallback, options: {
160
- excludeLocal: boolean;
167
+ excludeLocal?: boolean | undefined;
161
168
  }): any;
162
169
  /**
163
170
  * Observe all the {@link SharedState} instances of given {@link SharedStateClassName}
@@ -169,7 +176,7 @@ declare class BaseStateManager {
169
176
  * @param {stateManagerObserveCallback} callback - Function to execute when a
170
177
  * new {@link SharedState} is created on the network.
171
178
  * @param {object} options - Options.
172
- * @param {boolean} options.excludeLocal=false - If set to true, exclude states
179
+ * @param {boolean} [options.excludeLocal=false] - If set to true, exclude states
173
180
  * created by the same node from the collection.
174
181
  * @example
175
182
  * client.stateManager.observe('my-shared-state-class', async (className, stateId) => {
@@ -177,7 +184,7 @@ declare class BaseStateManager {
177
184
  * }, { excludeLocal: true });
178
185
  */
179
186
  observe(className: SharedStateClassName, callback: stateManagerObserveCallback, options: {
180
- excludeLocal: boolean;
187
+ excludeLocal?: boolean | undefined;
181
188
  }): any;
182
189
  /**
183
190
  * Returns a collection of all the states created from a given shared state class.
@@ -195,48 +202,28 @@ declare class BaseStateManager {
195
202
  *
196
203
  * @overload
197
204
  * @param {SharedStateClassName} className - Name of the shared state class.
198
- * @param {SharedStateParameterName[]} filter - Filter parameter of interest for each
199
- * state of the collection.
200
- * @returns {Promise<SharedStateCollection>}
201
- *
202
- * @example
203
- * const collection = await client.stateManager.getCollection(className, ['my-param']);
204
- */
205
- getCollection(className: SharedStateClassName, filter: SharedStateParameterName[]): Promise<SharedStateCollection>;
206
- /**
207
- * Returns a collection of all the states created from a given shared state class.
208
- *
209
- * @overload
210
- * @param {SharedStateClassName} className - Name of the shared state class.
211
- * @param {object} options - Options.
212
- * @param {boolean} options.excludeLocal=false - If set to true, exclude states
205
+ * @param {object} [options={}] - Options.
206
+ * @param {boolean} [options.excludeLocal=false] - If set to true, exclude states
213
207
  * created by the same node from the collection.
208
+ * @param {string[]} [options.whiteList] - White list of parameter names to track (as precedence over `blackList`).
209
+ * @param {string[]} [options.blackList] - Black list of parameter names to ignore.
214
210
  * @returns {Promise<SharedStateCollection>}
215
211
  *
216
212
  * @example
217
- * const collection = await client.stateManager.getCollection(className, { excludeLocal: true });
213
+ * const collection = await client.stateManager.getCollection(className, {
214
+ * blackList: ['my-param'],
215
+ * excludeLocal: true,
216
+ * });
218
217
  */
219
- getCollection(className: SharedStateClassName, options: {
220
- excludeLocal: boolean;
221
- }): Promise<SharedStateCollection>;
218
+ getCollection(className: SharedStateClassName, options?: {
219
+ excludeLocal?: boolean | undefined;
220
+ whiteList?: string[] | undefined;
221
+ blackList?: string[] | undefined;
222
+ } | undefined): Promise<SharedStateCollection>;
222
223
  /**
223
- * Returns a collection of all the states created from a given shared state class.
224
- *
225
- * @overload
226
- * @param {SharedStateClassName} className - Name of the shared state class.
227
- * @param {SharedStateParameterName[]} filter - Filter parameter of interest for each
228
- * state of the collection.
229
- * @param {object} options - Options.
230
- * @param {boolean} options.excludeLocal=false - If set to true, exclude states
231
- * created by the same node from the collection.
232
- * @returns {Promise<SharedStateCollection>}
233
- *
234
- * @example
235
- * const collection = await client.stateManager.getCollection(className, ['my-param'], { excludeLocal: true });
224
+ * @deprecated Use {@link BaseStateManager#getClassDescription} instead.
236
225
  */
237
- getCollection(className: SharedStateClassName, filter: SharedStateParameterName[], options: {
238
- excludeLocal: boolean;
239
- }): Promise<SharedStateCollection>;
226
+ getSchema(className: any): Promise<any>;
240
227
  /** @private */
241
228
  private [kStateManagerDeleteState];
242
229
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"BaseStateManager.d.ts","sourceRoot":"","sources":["../../src/common/BaseStateManager.js"],"names":[],"mappings":"AAgCA,8CAAyE;AACzE,qDAAwF;AAExF,gDAA6E;;;;;;;;;;;AAE7E;;;;;;;;GAQG;AACH;;;;;GAKG;AAEH,eAAe;AACf;IAuLE;;;;;;OAMG;IACH,2CAHW,GAAC,QAKX;IAED;;;;;;;;OAQG;IACH,+BANW,oBAAoB,GAEnB,2BAA2B,CAatC;IAED;;OAEG;IACH,wCAGC;IAED;;;;;;;;OAQG;IACH,kBANW,oBAAoB;;QAElB,OAAO,CAAC,WAAW,CAAC,CAahC;;;;;;;;;;;IAKE,kBACQ,oBAAoB,GAClB,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;IAMA,kBACQ,oBAAoB,WACpB,MAAM,GACJ,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;IAMA,kBACQ,oBAAoB,UACpB,MAAM,EAAE,GACN,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;;IAMA,kBACQ,oBAAoB,WACpB,MAAM,UACN,MAAM,EAAE,GACN,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;;;IAsEA,kBACQ,2BAA2B,OAEnC;;;;;;;;;;;;;;;IAWA,mBACQ,oBAAoB,YAEpB,2BAA2B,OAEnC;;;;;;;;;;;;;;;;;;IASA,kBACQ,2BAA2B,WAGnC;QAAyB,YAAY,EAA7B,OAAO;KAEf,OAAA;;;;;;;;;;;;;;;;;;IAWA,mBACQ,oBAAoB,YAEpB,2BAA2B,WAGnC;QAAyB,YAAY,EAA7B,OAAO;KAEf,OAAA;;;;;;;;;;;IAwJA,yBACQ,oBAAoB,GAClB,OAAO,CAAC,qBAAqB,CAAC,CAExC;;;;;;;;;;;;;IAMA,yBACQ,oBAAoB,UACpB,wBAAwB,EAAE,GAExB,OAAO,CAAC,qBAAqB,CAAC,CAExC;;;;;;;;;;;;;;IAMA,yBACQ,oBAAoB,WAE5B;QAAyB,YAAY,EAA7B,OAAO;KAEf,GAAU,OAAO,CAAC,qBAAqB,CAAC,CAExC;;;;;;;;;;;;;;;;IAMA,yBACQ,oBAAoB,UACpB,wBAAwB,EAAE,WAGlC;QAAyB,YAAY,EAA7B,OAAO;KAEf,GAAU,OAAO,CAAC,qBAAqB,CAAC,CAExC;IA7jBH,eAAe;IACf,mCAEC;IAED;;;;;;;OAOG;IACH,4BA2IC;IA5KC,eAAe;IACf,8BAAgC;;CAupBnC;wBAjtBuB,kBAAkB;kCAGnC,4BAA4B"}
1
+ {"version":3,"file":"BaseStateManager.d.ts","sourceRoot":"","sources":["../../src/common/BaseStateManager.js"],"names":[],"mappings":"AA+BA,8CAAyE;AACzE,qDAAwF;AACxF,gEAA6H;AAE7H,gDAA6E;;;;;;;;;;;AAG7E;;;;;;;;GAQG;AACH;;;;;GAKG;AAEH,eAAe;AACf;IA6EE;;;;;;OAMG;IACH,2CAHW,GAAC,QAKX;IAED;;;;;;;;OAQG;IACH,+BANW,oBAAoB,GAEnB,2BAA2B,CAatC;IAYD;;;;;;;;OAQG;IACH,kBANW,oBAAoB;;QAElB,OAAO,CAAC,WAAW,CAAC,CAahC;;;;;;;;;;;IAyBE,kBACQ,oBAAoB,GAClB,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;IAMA,kBACQ,oBAAoB,WACpB,MAAM,GACJ,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;;;IAMA,kBACQ,oBAAoB;;;oBAIlB,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;;;;IAMA,kBACQ,oBAAoB,WACpB,MAAM;;;oBAIJ,OAAO,CAAC,WAAW,CAAC,CAE9B;;;;;;;;;;;;;;IAgHA,kBACQ,2BAA2B,OAEnC;;;;;;;;;;;;;;;IAWA,mBACQ,oBAAoB,YAEpB,2BAA2B,OAEnC;;;;;;;;;;;;;;;;;;IASA,kBACQ,2BAA2B,WAGnC;QAA0B,YAAY;KAEtC,OAAA;;;;;;;;;;;;;;;;;;IAWA,mBACQ,oBAAoB,YAEpB,2BAA2B,WAGnC;QAA0B,YAAY;KAEtC,OAAA;;;;;;;;;;;IA4NA,yBACQ,oBAAoB,GAClB,OAAO,CAAC,qBAAqB,CAAC,CAExC;;;;;;;;;;;;;;;;;;;IAMA,yBACQ,oBAAoB;;;;oBAMlB,OAAO,CAAC,qBAAqB,CAAC,CAExC;IAqFH;;OAEG;IACH,wCAGC;IA5qBD,eAAe;IACf,mCAEC;IAED;;;;;;;OAOG;IACH,4BAyBC;IA3CC,eAAe;IACf,8BAAgC;;CAirBnC;wBA5uBuB,kBAAkB;kCAGnC,4BAA4B"}
@@ -3,7 +3,7 @@ export default SharedState;
3
3
  /**
4
4
  * Callback executed when updates are applied on a {@link SharedState}.
5
5
  */
6
- export type sharedStateOnUpdateCallback = (newValues: Object, oldValues: Object) => any;
6
+ export type sharedStateOnUpdateCallback = (newValues: Object | any, oldValues: Object | any, unsubscribe: sharedStateDeleteOnUpdateCallback) => any;
7
7
  /**
8
8
  * Delete the registered {@link sharedStateOnUpdateCallback}.
9
9
  */
@@ -12,10 +12,14 @@ export type sharedStateDeleteOnUpdateCallback = () => any;
12
12
  * Callback executed when updates are applied on a {@link SharedState}.
13
13
  *
14
14
  * @callback sharedStateOnUpdateCallback
15
- * @param {Object} newValues - Key / value pairs of the updates that have been
16
- * applied to the state.
17
- * @param {Object} oldValues - Key / value pairs of the updated params before
18
- * the updates has been applied to the state.
15
+ * @param {Object|any} newValues - Key / value pairs of the updates that have been
16
+ * applied to the state, or single value if the callback has been registered against
17
+ * a parameter name filter.
18
+ * @param {Object|any} oldValues - Key / value pairs of the updated params before
19
+ * the updates has been applied to the state, or single value if the callback has been
20
+ * registered against a parameter name filter.
21
+ * @param {sharedStateDeleteOnUpdateCallback} unsubscribe - Reference to unsubscribe
22
+ * function returned by the `SharedState#onUpdate` method.
19
23
  */
20
24
  /**
21
25
  * Delete the registered {@link sharedStateOnUpdateCallback}.
@@ -79,16 +83,6 @@ export type sharedStateDeleteOnUpdateCallback = () => any;
79
83
  * ```
80
84
  */
81
85
  declare class SharedState {
82
- constructor({ stateId, instanceId, className, classDescription, isOwner, manager, initValues, filter, }: {
83
- stateId: any;
84
- instanceId: any;
85
- className: any;
86
- classDescription: any;
87
- isOwner: any;
88
- manager: any;
89
- initValues: any;
90
- filter: any;
91
- });
92
86
  /**
93
87
  * Id of the state
94
88
  * @type {Number}
@@ -128,10 +122,6 @@ declare class SharedState {
128
122
  * const paramDescription = state.getDescription('my-param');
129
123
  */
130
124
  getDescription(paramName?: string): SharedStateClassDescription | SharedStateParameterDescription;
131
- /**
132
- * @deprecated Use {@link SharedState#getDescription} instead.
133
- */
134
- getSchema(paramName?: null): any;
135
125
  /**
136
126
  * Update the values of the state.
137
127
  *
@@ -255,26 +245,36 @@ declare class SharedState {
255
245
  */
256
246
  delete(): Promise<any>;
257
247
  /**
258
- * Subscribe to state updates.
248
+ * Subscribe to any updates in the state.
259
249
  *
250
+ * @overload
260
251
  * @param {sharedStateOnUpdateCallback} callback
261
252
  * Callback to execute when an update is applied on the state.
262
253
  * @param {Boolean} [executeListener=false] - Execute the callback immediately
263
254
  * with current state values. Note that `oldValues` will be set to `{}`.
264
255
  * @returns {sharedStateDeleteOnUpdateCallback}
265
256
  * @example
266
- * const unsubscribe = state.onUpdate(async (newValues, oldValues) => {
267
- * for (let [key, value] of Object.entries(newValues)) {
268
- * switch (key) {
269
- * // do something
270
- * }
271
- * }
257
+ * state.onUpdate(updates => {
258
+ * // ...
272
259
  * });
260
+ */
261
+ onUpdate(callback: sharedStateOnUpdateCallback, executeListener?: boolean | undefined): sharedStateDeleteOnUpdateCallback;
262
+ /**
263
+ * Subscribe to updates in the state filtered by a given parameter name.
273
264
  *
274
- * // later
275
- * unsubscribe();
265
+ * @overload
266
+ * @param {SharedStateParameterName} paramName
267
+ * @param {sharedStateOnUpdateCallback} callback
268
+ * Callback to execute when an update is applied on the state.
269
+ * @param {Boolean} [executeListener=false] - Execute the callback immediately
270
+ * with current state values. Note that `oldValues` will be set to `{}`.
271
+ * @returns {sharedStateDeleteOnUpdateCallback}
272
+ * @example
273
+ * state.onUpdate('my-param', myValue => {
274
+ * // ...
275
+ * });
276
276
  */
277
- onUpdate(listener: any, executeListener?: boolean): sharedStateDeleteOnUpdateCallback;
277
+ onUpdate(paramName: SharedStateParameterName, callback: sharedStateOnUpdateCallback, executeListener?: boolean | undefined): sharedStateDeleteOnUpdateCallback;
278
278
  /**
279
279
  * Register a function to execute when detaching from the state. The function
280
280
  * will be executed before the `detach` promise resolves.
@@ -292,6 +292,25 @@ declare class SharedState {
292
292
  * @param {Function} callback - Callback to execute when the state is deleted.
293
293
  */
294
294
  onDelete(callback: Function): () => boolean;
295
+ /**
296
+ * Wait for a given condition in the state of the SharedState instance.
297
+ * If the state watches the condition when `waitFor` is called, the promise is
298
+ * resolved immediately.
299
+ *
300
+ * @note - mark as private until tested in real-world
301
+ *
302
+ * @private
303
+ * @param {object} condition - Condition to be meet in the state for the
304
+ * returned promise to resolve.
305
+ * @param {object} condition - Timeout (in milliseconds) that trigger the rejection
306
+ * of the returned promise.
307
+ * @return {Promise}
308
+ */
309
+ private waitFor;
310
+ /**
311
+ * @deprecated Use {@link SharedState#getDescription} instead.
312
+ */
313
+ getSchema(paramName?: null): any;
295
314
  /** @private */
296
315
  private [kSharedStatePromiseStore];
297
316
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"SharedState.d.ts","sourceRoot":"","sources":["../../src/common/SharedState.js"],"names":[],"mappings":"AA2BA,qDAAwF;;;;;sDAM7E,MAAM,aAEN,MAAM;;;;;AANjB;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH;IAiBE;;;;;;;;;OAkKC;IAED;;;OAGG;IACH,iBAEC;IAED;;;OAGG;IACH,wBAEC;IAED;;OAEG;IACH,yBAGC;IAED;;;OAGG;IACH,uBAEC;IAED;;;;;OAKG;IACH,2BAUC;IAwED;;;;;;;;;;;OAWG;IACH,2BARW,MAAM,GAEL,2BAA2B,GAAC,+BAA+B,CAYtE;IAED;;OAEG;IACH,iCAGC;;;;;;;;;;;IAQE,aACQ,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAC3B;;;;;;;;;;;;IAOE,UACQ,wBAAwB,SACxB,GAAC,GACC,OAAO,CAAC,MAAM,CAAC,CAC3B;IA8KD;;;;;;;;;;;;;;OAcG;IACH,UANW,wBAAwB,GACvB,GAAG,CAiBd;IAED;;;;;;;;;;;;;;OAcG;IACH,gBANW,wBAAwB,GACvB,GAAG,CAiBd;IAED;;;;;;;;OAQG;IACH,aAJY,MAAM,CAgBjB;IAED;;;;;;;;;;;;OAYG;IACH,mBAJY,MAAM,CAgBjB;IAED;;;;;;;OAOG;IACH,iBAJY,MAAM,CAMjB;IAED;;;;;;OAMG;IACH,eAJY,MAAM,CAMjB;IAED;;;;;;;;OAQG;IACH,uBAiBC;IAED;;;;;;;;;;;;;;OAcG;IACH,uBAUC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,oDAba,iCAAiC,CAkC7C;IAED;;;;;;;OAOG;IACH,4CAGC;IAED;;;;;;OAMG;IACH,4CAOC;IAluBC,eAAe;IACf,mCAAwE;;CAkuB3E"}
1
+ {"version":3,"file":"SharedState.d.ts","sourceRoot":"","sources":["../../src/common/SharedState.js"],"names":[],"mappings":"AAmCA,qDAAwF;;;;;sDAM7E,MAAM,GAAC,GAAG,aAGV,MAAM,GAAC,GAAG,eAGV,iCAAiC;;;;;AAV5C;;;;;;;;;;;;GAYG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH;IAoSE;;;OAGG;IACH,iBAEC;IAED;;;OAGG;IACH,wBAEC;IAED;;OAEG;IACH,yBAGC;IAED;;;OAGG;IACH,uBAEC;IAED;;;;;OAKG;IACH,2BAUC;IAED;;;;;;;;;;;OAWG;IACH,2BARW,MAAM,GAEL,2BAA2B,GAAC,+BAA+B,CAYtE;;;;;;;;;;;IAQE,aACQ,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAC3B;;;;;;;;;;;;IAOE,UACQ,wBAAwB,SACxB,GAAC,GACC,OAAO,CAAC,MAAM,CAAC,CAC3B;IA6KD;;;;;;;;;;;;;;OAcG;IACH,UANW,wBAAwB,GACvB,GAAG,CAkBd;IAED;;;;;;;;;;;;;;OAcG;IACH,gBANW,wBAAwB,GACvB,GAAG,CAkBd;IAED;;;;;;;;OAQG;IACH,aAJY,MAAM,CAOjB;IAED;;;;;;;;;;;;OAYG;IACH,mBAJY,MAAM,CAOjB;IAED;;;;;;;OAOG;IACH,iBAJY,MAAM,CAMjB;IAED;;;;;;OAMG;IACH,eAJY,MAAM,CAMjB;IAED;;;;;;;;OAQG;IACH,uBAiBC;IAED;;;;;;;;;;;;;;OAcG;IACH,uBAUC;;;;;;;;;;;;;;;IAKE,mBACQ,2BAA2B,0CAIzB,iCAAiC,CAC3C;;;;;;;;;;;;;;;;IAQA,oBACQ,wBAAwB,YACxB,2BAA2B,0CAIzB,iCAAiC,CAC3C;IAwDH;;;;;;;OAOG;IACH,4CAGC;IAED;;;;;;OAMG;IACH,4CAOC;IAED;;;;;;;;;;;;;OAaG;IACH,gBAgCC;IAMD;;OAEG;IACH,iCAGC;IAx1BC,eAAe;IACf,mCAAwE;;CAy1B3E"}
@@ -4,10 +4,14 @@
4
4
  *
5
5
  * @callback sharedStateCollectionOnUpdateCallback
6
6
  * @param {SharedState} state - The shared state instance that triggered the update.
7
- * @param {Object} newValues - Key / value pairs of the updates that have been
8
- * applied to the state.
9
- * @param {Object} oldValues - Key / value pairs of the updated params before
10
- * the updates has been applied to the state.
7
+ * @param {Object|any} newValues - Key / value pairs of the updates that have been
8
+ * applied to the state, or single value if the callback has been registered against
9
+ * a parameter name filter.
10
+ * @param {Object|any} oldValues - Key / value pairs of the updated params before
11
+ * the updates has been applied to the state, or single value if the callback has been
12
+ * registered against a parameter name filter.
13
+ * @param {sharedStateCollectionDeleteOnUpdateCallback} unsubscribe - Reference to unsubscribe
14
+ * function returned by the `SharedStateCollection#onUpdate` method.
11
15
  */
12
16
  /**
13
17
  * Delete the registered {@link sharedStateCollectionOnUpdateCallback} when executed.
@@ -53,7 +57,7 @@ export default SharedStateCollection;
53
57
  * Callback to execute when an update is triggered on one of the shared states
54
58
  * of the collection.
55
59
  */
56
- export type sharedStateCollectionOnUpdateCallback = (state: SharedState, newValues: Object, oldValues: Object) => any;
60
+ export type sharedStateCollectionOnUpdateCallback = (state: SharedState, newValues: Object | any, oldValues: Object | any, unsubscribe: sharedStateCollectionDeleteOnUpdateCallback) => any;
57
61
  /**
58
62
  * Delete the registered {@link sharedStateCollectionOnUpdateCallback} when executed.
59
63
  */
@@ -102,7 +106,7 @@ export type sharedStateCollectionDeleteOnChangeCallback = () => any;
102
106
  * @hideconstructor
103
107
  */
104
108
  declare class SharedStateCollection {
105
- constructor(stateManager: any, className: any, filter?: null, options?: {});
109
+ constructor(stateManager: any, className: any, options?: {});
106
110
  /**
107
111
  * Size of the collection, alias `size`
108
112
  * @type {number}
@@ -207,8 +211,22 @@ declare class SharedStateCollection {
207
211
  */
208
212
  set(name: SharedStateParameterName, value: any): Promise<Array<Object>>;
209
213
  /**
210
- * Register a function to execute when any shared state of the collection is updated.
214
+ * Subscribe to any updates in the collection.
211
215
  *
216
+ * @overload
217
+ * @param {sharedStateCollectionOnUpdateCallback}
218
+ * callback - Callback to execute when an update is applied on a state.
219
+ * @param {Boolean} [executeListener=false] - Execute the callback immediately
220
+ * with current state values. Note that `oldValues` will be set to `{}`.
221
+ * @returns {sharedStateCollectionDeleteOnUpdateCallback} - Function that delete
222
+ * the registered listener when executed.
223
+ */
224
+ onUpdate(callback: sharedStateCollectionOnUpdateCallback, executeListener?: boolean | undefined): sharedStateCollectionDeleteOnUpdateCallback;
225
+ /**
226
+ * Subscribe to updates in the collection filtered by a given parameter name.
227
+ *
228
+ * @overload
229
+ * @param {SharedStateParameterName} paramName
212
230
  * @param {sharedStateCollectionOnUpdateCallback}
213
231
  * callback - Callback to execute when an update is applied on a state.
214
232
  * @param {Boolean} [executeListener=false] - Execute the callback immediately
@@ -216,7 +234,7 @@ declare class SharedStateCollection {
216
234
  * @returns {sharedStateCollectionDeleteOnUpdateCallback} - Function that delete
217
235
  * the registered listener when executed.
218
236
  */
219
- onUpdate(callback: sharedStateCollectionOnUpdateCallback, executeListener?: boolean): sharedStateCollectionDeleteOnUpdateCallback;
237
+ onUpdate(paramName: SharedStateParameterName, callback: sharedStateCollectionOnUpdateCallback, executeListener?: boolean | undefined): sharedStateCollectionDeleteOnUpdateCallback;
220
238
  /**
221
239
  * Register a function to execute when a shared state is attached to the collection,
222
240
  * i.e. when a node creates a new state from same {@link SharedState} class.
@@ -1 +1 @@
1
- {"version":3,"file":"SharedStateCollection.d.ts","sourceRoot":"","sources":["../../src/common/SharedStateCollection.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH;;;;GAIG;AAEH;;;;;GAKG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH,uDAA4F;;;;;;4DApDjF,WAAW,aACX,MAAM,aAEN,MAAM;;;;;;;;4DAcN,WAAW;;;;;;;;;4DAcX,WAAW;;;;;;;;;;;;;AAuBtB;;;;;;;;;;;;;;;;;GAiBG;AACH;IAaE,4EAKC;IAuCD;;;;OAIG;IACH,uBAHU,MAAM,CAKf;IAED;;;OAGG;IACH,YAFU,MAAM,CAIf;IAED;;;OAGG;IACH,wBAEC;IAED;;OAEG;IACH,yBAGC;IAED;;OAEG;IACH,iCAGC;IAED;;;;;;;;;;;OAWG;IACH,2BARW,MAAM,GAEL,2BAA2B,GAAC,+BAA+B,CAgBtE;IAED;;;;;;OAMG;IACH,eAJY,MAAM,CAUjB;IAED;;;OAGG;IACH,aAFY,MAAM,EAAE,CAInB;IAED;;;;;;;;;;OAUG;IACH,mBAFY,MAAM,EAAE,CAInB;IAED;;;;;OAKG;IACH,mBAFY,GAAG,EAAE,CAMhB;IAED;;;;;;;;;OASG;IACH,yBAFY,GAAG,EAAE,CAMhB;;;;;;;;;;;IAQE,aACQ,MAAM,GACJ,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAClC;;;;;;;;;;;;IAOE,UACQ,wBAAwB,SACxB,GAAC,GACC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAClC;IAwBD;;;;;;;;;OASG;IACH,mBAPW,qCAAqC,8BAInC,2CAA2C,CAyBvD;IAED;;;;;;;;;;OAUG;IACH,mBAPW,qCAAqC,oBAErC,OAAO,GAEL,2CAA2C,CAWvD;IAED;;;;;;;;OAQG;IACH,mBALW,qCAAqC,GAEnC,2CAA2C,CAOvD;IAED;;;;;;;;;;;OAWG;IACH,mBARW,qCAAqC,8BAEnC,2CAA2C,CAcvD;IAED;;;OAGG;IACH,wBAUC;IAED;;;;;OAKG;IACH,8BAEC;IAED;;;;;;OAMG;IACH,2BAEC;IAED;;;;;;;OAOG;IACH,8BAEC;IAED;;;;OAIG;IACH,2BAEC;IAED;;;;;;;OAOG;IACH,0BAEC;IAED;;;;;;;;;;;;;;OAcG;IACH,OAVa,CAAC,gCAKH,CAAC,mBAGA,CAAC,CASZ;IA5YD,eAAe;IACf,qCAkCC;IA2WD;;OAEG;IACH;;;;;MAYC;;CACF"}
1
+ {"version":3,"file":"SharedStateCollection.d.ts","sourceRoot":"","sources":["../../src/common/SharedStateCollection.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AAEH;;;;;GAKG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH,uDAA4F;;;;;;4DAxDjF,WAAW,aACX,MAAM,GAAC,GAAG,aAGV,MAAM,GAAC,GAAG,eAGV,2CAA2C;;;;;;;;4DAc3C,WAAW;;;;;;;;;4DAcX,WAAW;;;;;;;;;;;;;AAuBtB;;;;;;;;;;;;;;;;;GAiBG;AACH;IAaE,6DAQC;IA4CD;;;;OAIG;IACH,uBAHU,MAAM,CAKf;IAED;;;OAGG;IACH,YAFU,MAAM,CAIf;IAED;;;OAGG;IACH,wBAEC;IAED;;OAEG;IACH,yBAGC;IAED;;OAEG;IACH,iCAGC;IAED;;;;;;;;;;;OAWG;IACH,2BARW,MAAM,GAEL,2BAA2B,GAAC,+BAA+B,CAgBtE;IAED;;;;;;OAMG;IACH,eAJY,MAAM,CAUjB;IAED;;;OAGG;IACH,aAFY,MAAM,EAAE,CAInB;IAED;;;;;;;;;;OAUG;IACH,mBAFY,MAAM,EAAE,CAInB;IAED;;;;;OAKG;IACH,mBAFY,GAAG,EAAE,CAMhB;IAED;;;;;;;;;OASG;IACH,yBAFY,GAAG,EAAE,CAMhB;;;;;;;;;;;IAQE,aACQ,MAAM,GACJ,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAClC;;;;;;;;;;;;IAOE,UACQ,wBAAwB,SACxB,GAAC,GACC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAClC;;;;;;;;;;;;IA2BE,mBACQ,qCAAqC,0CAInC,2CAA2C,CAEvD;;;;;;;;;;;;;IAIE,oBACQ,wBAAwB,YACxB,qCAAqC,0CAInC,2CAA2C,CAEvD;IA6CD;;;;;;;;;;OAUG;IACH,mBAPW,qCAAqC,oBAErC,OAAO,GAEL,2CAA2C,CAWvD;IAED;;;;;;;;OAQG;IACH,mBALW,qCAAqC,GAEnC,2CAA2C,CAOvD;IAED;;;;;;;;;;;OAWG;IACH,mBARW,qCAAqC,8BAEnC,2CAA2C,CAcvD;IAED;;;OAGG;IACH,wBAUC;IAED;;;;;OAKG;IACH,8BAEC;IAED;;;;;;OAMG;IACH,2BAEC;IAED;;;;;;;OAOG;IACH,8BAEC;IAED;;;;OAIG;IACH,2BAEC;IAED;;;;;;;OAOG;IACH,0BAEC;IAED;;;;;;;;;;;;;;OAcG;IACH,OAVa,CAAC,gCAKH,CAAC,mBAGA,CAAC,CASZ;IAlbD,eAAe;IACf,qCA6BC;IAsZD;;OAEG;IACH;;;;;MAYC;;CACF"}