@soundworks/core 5.7.0 → 5.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v5.8.0 - 2026-10-01
4
+
5
+ - Feat: SharedState#WaitFor accept arbitrary function as condition
6
+
3
7
  ## v5.7.0 - 2026-10-01
4
8
 
5
9
  - Refactor: SharedState callback and instantiation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soundworks/core",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "description": "Open-source creative coding framework for distributed applications based on Web technologies",
5
5
  "collaborators": [
6
6
  "Benjamin Matuszewski",
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  isPlainObject,
3
3
  isString,
4
+ isFunction,
4
5
  } from '@ircam/sc-utils';
5
6
 
6
7
  import ParameterBag from './ParameterBag.js';
@@ -383,19 +384,25 @@ class SharedState {
383
384
  }
384
385
 
385
386
  #checkPendingWaitForConditions() {
386
- const values = this.getValuesUnsafe();
387
+ const values = this.getValues();
387
388
 
388
389
  this.#waitForConditions.forEach(payload => {
389
390
  const { resolve, condition, timeoutId } = payload;
390
- let match = true;
391
+ let match;
391
392
 
392
- for (let [key, value] of Object.entries(condition)) {
393
- if (values[key] !== value) {
394
- match = false;
393
+ if (isFunction(condition)) {
394
+ match = condition(values);
395
+ } else {
396
+ match = true;
397
+
398
+ for (let [key, value] of Object.entries(condition)) {
399
+ if (values[key] !== value) {
400
+ match = false;
401
+ }
395
402
  }
396
403
  }
397
404
 
398
- if (match) {
405
+ if (match === true) {
399
406
  clearTimeout(timeoutId);
400
407
  this.#waitForConditions.delete(payload);
401
408
  resolve();
@@ -954,14 +961,16 @@ class SharedState {
954
961
  *
955
962
  * @private
956
963
  * @param {object} condition - Condition to be meet in the state for the
957
- * returned promise to resolve.
958
- * @param {object} condition - Timeout (in milliseconds) that trigger the rejection
964
+ * returned promise to resolve. The condition is either a function which returns
965
+ * `true` when the condition is met or an object that describe a desired state
966
+ * of a subset the `SharedState` values.
967
+ * @param {object} timeout - Timeout (in milliseconds) that trigger the rejection
959
968
  * of the returned promise.
960
969
  * @return {Promise}
961
970
  */
962
971
  waitFor(condition, timeout = null) {
963
- if (!isPlainObject(condition)) {
964
- throw new TypeError(`Cannot execute 'waitFor' on SharedState: argument 0 must be an object`);
972
+ if (!isPlainObject(condition) && !isFunction(condition)) {
973
+ throw new TypeError(`Cannot execute 'waitFor' on SharedState: argument 0 must be either a function or an object`);
965
974
  }
966
975
 
967
976
  if (timeout !== null && (!Number.isFinite(timeout) || timeout <= 0)) {
@@ -1,2 +1,2 @@
1
1
  // [WARNING] This file is generated, do not edit
2
- export default '5.7.0';
2
+ export default '5.8.0';
@@ -301,8 +301,10 @@ declare class SharedState {
301
301
  *
302
302
  * @private
303
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
304
+ * returned promise to resolve. The condition is either a function which returns
305
+ * `true` when the condition is met or an object that describe a desired state
306
+ * of a subset the `SharedState` values.
307
+ * @param {object} timeout - Timeout (in milliseconds) that trigger the rejection
306
308
  * of the returned promise.
307
309
  * @return {Promise}
308
310
  */
@@ -1 +1 @@
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;IA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;;;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;;;;;;;;;;;;;;;OAeG;IACH,gBAgCC;IAMD;;OAEG;IACH,iCAGC;IAh2BC,eAAe;IACf,mCAAwE;;CAi2B3E"}
@@ -1,3 +1,3 @@
1
- declare const _default: "5.7.0";
1
+ declare const _default: "5.8.0";
2
2
  export default _default;
3
3
  //# sourceMappingURL=version.d.ts.map