Update DisplaySetService

This commit is contained in:
James A. Petts committed 2020-05-19 10:30:16 +02:00
1 parent 2b41d64e85
commit aec30e0db1
4 files changed
+226 -138

No files matched your search

@@ -1,5 +1,6 @@
import log from '../../log';
import guid from '../../utils/guid';
import pubSubServiceInterface from '../pubSubServiceInterface';
/**
* Measurement source schema
@@ -73,6 +74,8 @@ class MeasurementService {
enumerable: true,
configurable: false,
});
Object.assign(this, pubSubServiceInterface);
}
/**
@@ -341,26 +344,26 @@ class MeasurementService {
* @param {string} eventName The name of the event
* @param {Function} callback Events callback
* @return {Object} Observable object with actions
*/
subscribe(eventName, callback) {
if (this._isValidEvent(eventName)) {
const listenerId = guid();
const subscription = { id: listenerId, callback };
// */
// subscribe(eventName, callback) {
// if (this._isValidEvent(eventName)) {
// const listenerId = guid();
// const subscription = { id: listenerId, callback };
console.info(`Subscribing to '${eventName}'.`);
if (Array.isArray(this.listeners[eventName])) {
this.listeners[eventName].push(subscription);
} else {
this.listeners[eventName] = [subscription];
}
// console.info(`Subscribing to '${eventName}'.`);
// if (Array.isArray(this.listeners[eventName])) {
// this.listeners[eventName].push(subscription);
// } else {
// this.listeners[eventName] = [subscription];
// }
return {
unsubscribe: () => this._unsubscribe(eventName, listenerId),
};
} else {
throw new Error(`Event ${eventName} not supported.`);
}
}
// return {
// unsubscribe: () => this._unsubscribe(eventName, listenerId),
// };
// } else {
// throw new Error(`Event ${eventName} not supported.`);
// }
// }
_getMappingByMeasurementSource(measurementId, definition) {
const measurement = this.getMeasurement(measurementId);
@@ -450,23 +453,23 @@ class MeasurementService {
* Unsubscribe to measurement updates.
*
* @param {string} eventName The name of the event
* @param {string} listenerId The listeners id
* @return void
*/
_unsubscribe(eventName, listenerId) {
if (!this.listeners[eventName]) {
return;
}
// * @param {string} listenerId The listeners id
// * @return void
// */
// _unsubscribe(eventName, listenerId) {
// if (!this.listeners[eventName]) {
// return;
// }
const listeners = this.listeners[eventName];
if (Array.isArray(listeners)) {
this.listeners[eventName] = listeners.filter(
({ id }) => id !== listenerId
);
} else {
this.listeners[eventName] = undefined;
}
}
// const listeners = this.listeners[eventName];
// if (Array.isArray(listeners)) {
// this.listeners[eventName] = listeners.filter(
// ({ id }) => id !== listenerId
// );
// } else {
// this.listeners[eventName] = undefined;
// }
// }
/**
* Check if a given measurement data is valid.
@@ -490,10 +493,10 @@ class MeasurementService {
*
* @param {string} eventName The name of the event
* @return {boolean} Event name validation
*/
_isValidEvent(eventName) {
return Object.values(this.EVENTS).includes(eventName);
}
// */
// _isValidEvent(eventName) {
// return Object.values(this.EVENTS).includes(eventName);
// }
/**
* Converts object of objects to array.