remove connections api

pull/98/head
dperolio 2 years ago
parent 27a40cefb5
commit fa54f572be
No known key found for this signature in database
GPG Key ID: 4191689562D51409

@ -1,54 +0,0 @@
import { API } from '@vizality/entities';
export default class Connections extends API {
constructor () {
super();
this.connections = [];
this._module = 'API';
this._submodule = 'Connections';
}
get filter () {
return this.connections.filter.bind(this.connections);
}
stop () {
this.removeAllListeners();
delete vizality.api.connections;
}
get map () {
return this.connections.map.bind(this.connections);
}
get filter () {
return this.connections.filter.bind(this.connections);
}
registerConnection (connection) {
if (this.get(connection.type)) {
/* @todo: Use logger. */
throw new Error('This type of connection already exists!');
}
this.connections.push(connection);
}
unregisterConnection (type) {
this.connections = this.connections.filter(c => c.type !== type);
}
fetchAccounts (id) {
return Promise.all(
this.filter(c => c.enabled).map(c => c.fetchAccount(id))
);
}
get (type) {
const connections = {};
for (const element of this.connections) {
connections[element.type] = element;
}
return connections[type] || null;
}
}
Loading…
Cancel
Save