-
Notifications
You must be signed in to change notification settings - Fork 1
/
choose.js
51 lines (45 loc) · 1.38 KB
/
choose.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
"use strict";
module.exports = Choose;
function Choose(body, scope) {
this.choices = scope.argument.children;
this.choice = null;
this.choiceBody = null;
this.choiceScope = null;
this.body = body;
this.scope = scope;
this._value = null;
}
Object.defineProperty(Choose.prototype, "value", {
get: function () {
return this._value;
},
set: function (value) {
if (value != null && !this.choices[value]) {
throw new Error("Can't switch to non-existant option");
}
this._value = value;
if (this.choice) {
if (this.choice.destroy) {
this.choice.destroy();
}
this.body.removeChild(this.choiceBody);
this.choice = null;
this.choiceBody = null;
}
if (value != null) {
this.choiceBody = this.body.ownerDocument.createBody();
this.choiceScope = this.scope.nestComponents();
this.choice = new this.choices[value](this.choiceBody, this.choiceScope);
this.choiceScope.hookup(this.scope.id + ":" + value, this.choice);
this.body.appendChild(this.choiceBody);
}
}
});
Choose.prototype.destroy = function () {
for (var name in this.options) {
var child = this.options[name];
if (child.destroy) {
child.destroy();
}
}
};