forked from OpenLightingProject/open-fixture-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractChannel.js
69 lines (60 loc) · 1.75 KB
/
AbstractChannel.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
/** @ignore @typedef {import('./Fixture.js').default} Fixture */
/**
* Base class for channels.
* @abstract
*/
class AbstractChannel {
/**
* Create a new AbstractChannel instance. Call this from child classes as `super(key)`.
* @param {string} key The channel's identifier, must be unique in the fixture.
* @throws {TypeError} If the AbstractChannel is instantiated directly.
*/
constructor(key) {
if (this.constructor === AbstractChannel) {
throw new TypeError(`Cannot instantiate AbstractChannel directly`);
}
this._key = key;
this._pixelKey = null;
}
/**
* @abstract
* @returns {Fixture} The fixture instance this channel is associated to.
* @throws {TypeError} If this property is not overridden in child classes.
*/
get fixture() {
throw new TypeError(`Class ${this.constructor.name} must implement property fixture`);
}
/**
* @returns {string} The channel key.
*/
get key() {
return this._key;
}
/**
* Override this method for more sensible implementation.
* @returns {string} The channel key (as name).
*/
get name() {
return this._key;
}
/**
* @see {@link Fixture#uniqueChannelNames}
* @returns {string} Unique version of this channel's name.
*/
get uniqueName() {
return this.fixture.uniqueChannelNames[this.key];
}
/**
* @returns {string | null} The key of the pixel (group) that this channel is associated to. Defaults to null.
*/
get pixelKey() {
return this._pixelKey;
}
/**
* @param {string | null} pixelKey The key of the pixel (group) that this channel is associated to. Set to null to dereference a channel from a pixel (group).
*/
set pixelKey(pixelKey) {
this._pixelKey = pixelKey;
}
}
export default AbstractChannel;