forked from svt/bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkspaceRegistry.js
71 lines (62 loc) · 1.32 KB
/
WorkspaceRegistry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-FileCopyrightText: 2022 Sveriges Television AB
//
// SPDX-License-Identifier: MIT
const EventEmitter = require('events')
const Logger = require('./Logger')
const logger = new Logger({ name: 'WorkspaceRegistry' })
class WorkspaceRegistry extends EventEmitter {
/**
* Get the singleton instance
* of this class
* @returns { WorkspaceRegistry }
*/
static getInstance () {
if (!this._instance) {
this._instance = new WorkspaceRegistry()
}
return this._instance
}
constructor () {
super()
/**
* @private
*/
this._map = new Map()
}
/**
* Add a new workspace
* to the registry
* @param { Workspace } workspace
*/
add (workspace) {
this._map.set(workspace.id, workspace)
this.emit('add', workspace)
}
/**
* Get a workspace
* from the registry
* @param { String } id
* @returns { Workspace || undefined }
*/
get (id) {
return this._map.get(id)
}
/**
* Delete a workspace
* from the registry
* @param { String } id
*/
delete (id) {
logger.debug('Removing workspace with id', id)
this._map.delete(id)
}
/**
* Get an array of all workspaces
* currently in the registry
* @returns { Workspace[] }
*/
list () {
return Array.from(this._map.values())
}
}
module.exports = WorkspaceRegistry