-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreveal.js
45 lines (39 loc) · 1.31 KB
/
reveal.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
"use strict";
// TODO create scope for revealed body and add to owner whenever it is created.
// Destroy when retracted, recreate when revealed.
var O = require("pop-observe");
module.exports = Reveal;
function Reveal(body, scope) {
this.value = false;
this.observer = O.observePropertyChange(this, "value", this);
this.body = body;
this.scope = scope;
this.Component = scope.argument.component;
this.component = null;
this.componentBody = null;
this.componentScope = null;
}
Reveal.prototype.handleValuePropertyChange = function (value) {
this.clear();
if (value) {
this.componentScope = this.scope.nestComponents();
this.componentBody = this.body.ownerDocument.createBody();
this.component = new this.Component(this.componentBody, this.componentScope);
this.componentScope.hookup(this.scope.id + ":revelation", this.component);
this.body.appendChild(this.componentBody);
}
};
Reveal.prototype.clear = function clear() {
if (this.component) {
if (this.component.destroy) {
this.component.destroy();
}
this.body.removeChild(this.componentBody);
this.component = null;
this.componentBody = null;
}
};
Reveal.prototype.destroy = function () {
this.clear();
this.observer.cancel();
};