@soundworks/core
Advanced tools
Comparing version 3.1.0-beta.2 to 3.1.0-beta.3
@@ -15,2 +15,3 @@ "use strict"; | ||
// import types from './types'; | ||
// import shallowClone from 'shallow-clone'; | ||
@@ -186,2 +187,5 @@ /** | ||
* | ||
* Note that the `any` type always return a shallow copy of the state internal | ||
* value. Mutating the returned value will not modify the internal state. | ||
* | ||
* @property {String} [type='any'] - Parameter of any type. | ||
@@ -214,4 +218,4 @@ * @property {Mixed} default - Default value of the parameter. | ||
metas: {}, | ||
filterChange: true // immediate: false, | ||
filterChange: true, | ||
immediate: false | ||
}; | ||
@@ -429,6 +433,13 @@ exports.sharedOptions = sharedOptions; | ||
getValues() { | ||
return Object.assign({}, this._values); | ||
let values = {}; | ||
for (let name in this._values) { | ||
values[name] = this.get(name); | ||
} | ||
return values; | ||
} | ||
/** | ||
* Return the value of the given parameter. | ||
* Return the value of the given parameter. If the parameter is of `any` type, | ||
* a deep copy is returned. | ||
* | ||
@@ -445,3 +456,7 @@ * @param {String} name - Name of the parameter. | ||
return this._values[name]; | ||
if (this._schema[name].type === 'any') { | ||
return (0, _lodash.default)(this._values[name]); | ||
} else { | ||
return this._values[name]; | ||
} | ||
} | ||
@@ -492,2 +507,4 @@ /** | ||
* Reset a parameter to its initialization values. Reset all parameters if no argument. | ||
* @note - prefer `state.set(state.getInitValues())` | ||
* or `state.set(state.getDefaultValues())` | ||
* | ||
@@ -494,0 +511,0 @@ * @param {String} [name=null] - Name of the parameter to reset. |
@@ -49,16 +49,14 @@ "use strict"; | ||
client.transport.addListener(`${_sharedStateUtils.UPDATE_RESPONSE}-${id}-${this.remoteId}`, (reqId, updates, context) => { | ||
const updated = this._commit(updates, context, true, true); | ||
client.transport.addListener(`${_sharedStateUtils.UPDATE_RESPONSE}-${id}-${this.remoteId}`, async (reqId, updates, context) => { | ||
const updated = await this._commit(updates, context, true, true); | ||
(0, _sharedStateUtils.resolveRequest)(reqId, updated); | ||
}); // retrieve values but do not propagate to subscriptions | ||
client.transport.addListener(`${_sharedStateUtils.UPDATE_ABORT}-${id}-${this.remoteId}`, (reqId, updates, context) => { | ||
const updated = this._commit(updates, context, false, true); | ||
client.transport.addListener(`${_sharedStateUtils.UPDATE_ABORT}-${id}-${this.remoteId}`, async (reqId, updates, context) => { | ||
const updated = await this._commit(updates, context, false, true); | ||
(0, _sharedStateUtils.resolveRequest)(reqId, updated); | ||
}); | ||
client.transport.addListener(`${_sharedStateUtils.UPDATE_NOTIFICATION}-${id}-${this.remoteId}`, (updates, context) => { | ||
client.transport.addListener(`${_sharedStateUtils.UPDATE_NOTIFICATION}-${id}-${this.remoteId}`, async (updates, context) => { | ||
// cf. https://github.com/collective-soundworks/soundworks/issues/18 | ||
this._commit(updates, context, true, false); | ||
await this._commit(updates, context, true, false); | ||
}); // --------------------------------------------- | ||
@@ -149,3 +147,3 @@ // DELETE initiated by creator, or schema deleted | ||
_commit(updates, context, propagate = true, initiator = false) { | ||
async _commit(updates, context, propagate = true, initiator = false) { | ||
const newValues = {}; | ||
@@ -159,4 +157,8 @@ const oldValues = {}; | ||
event | ||
} = this._parameters.getSchema(name); | ||
} = this._parameters.getSchema(name); // @note 20211209 - we have an issue here server-side, because if the value | ||
// is an object or an array, the reference is shared by everybody, therefore | ||
// `changed` is always false and the new value is never propagated... | ||
// FIXED - `state.get` now returns a deep copy when `type` is `any` | ||
const oldValue = this._parameters.get(name); | ||
@@ -183,11 +185,34 @@ | ||
let promises = []; | ||
if (propagate && Object.keys(newValues).length > 0) { | ||
this._subscriptions.forEach(listener => listener(newValues, oldValues, context)); | ||
this._subscriptions.forEach(listener => { | ||
promises.push(listener(newValues, oldValues, context)); | ||
}); | ||
} | ||
await Promise.all(promises); | ||
return newValues; | ||
} | ||
/** | ||
* Updates values of the state. | ||
* Updates values of the state. Wait for all subscriptions to be resolved | ||
* before resolving itself, i.e.: | ||
* | ||
* ```js | ||
* const a = await server.stateManager.create('a'); | ||
* let asyncCallbackCalled = false; | ||
* | ||
* a.subscribe(updates => { | ||
* return new Promise(resolve => { | ||
* setTimeout(() => { | ||
* asyncCallbackCalled = true; | ||
* resolve(); | ||
* }, 100); | ||
* }); | ||
* }); | ||
* | ||
* await a.set({ bool: true }); | ||
* assert.equal(asyncCallbackCalled, true); | ||
* ``` | ||
* | ||
* @async | ||
@@ -194,0 +219,0 @@ * @param {Object} updates - key / value pairs of updates to apply to the state. |
{ | ||
"name": "@soundworks/core", | ||
"version": "3.1.0-beta.2", | ||
"version": "3.1.0-beta.3", | ||
"description": "full-stack javascript framework for distributed audio visual experiences on the web", | ||
@@ -42,3 +42,2 @@ "authors": [ | ||
"isomorphic-ws": "^4.0.1", | ||
"jsdoc-template": "^1.2.0", | ||
"keyv": "^4.0.3", | ||
@@ -45,0 +44,0 @@ "keyv-file": "^0.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164190
19
4051
- Removedjsdoc-template@^1.2.0
- Removedajv@6.12.6(transitive)
- Removedansi-gray@0.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedansi-wrap@0.1.0(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasync@1.5.2(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedbuffers@0.1.1(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.21.0.3(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddateformat@2.2.0(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgulp-css-base64@1.3.4(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisarray@0.0.11.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjsdoc-template@1.2.0(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedobject-assign@3.0.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedreadable-stream@1.1.142.3.8(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstring_decoder@0.10.311.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedvinyl@0.5.3(transitive)
- Removedxtend@4.0.2(transitive)