/
if-core.js
86 lines (63 loc) · 1.61 KB
/
if-core.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var IfCore = exports.IfCore = function () {
function IfCore(viewFactory, viewSlot) {
this.viewFactory = viewFactory;
this.viewSlot = viewSlot;
this.view = null;
this.bindingContext = null;
this.overrideContext = null;
this.showing = false;
}
IfCore.prototype.bind = function bind(bindingContext, overrideContext) {
this.bindingContext = bindingContext;
this.overrideContext = overrideContext;
};
IfCore.prototype.unbind = function unbind() {
if (this.view === null) {
return;
}
this.view.unbind();
if (!this.viewFactory.isCaching) {
this.showing = false;
return;
}
if (this.showing) {
this.showing = false;
this.viewSlot.remove(this.view, true, true);
} else {
this.view.returnToCache();
}
this.view = null;
};
IfCore.prototype._show = function _show() {
if (this.showing) {
return;
}
if (this.view === null) {
this.view = this.viewFactory.create();
}
if (!this.view.isBound) {
this.view.bind(this.bindingContext, this.overrideContext);
}
this.showing = true;
return this.viewSlot.add(this.view);
};
IfCore.prototype._hide = function _hide() {
var _this = this;
if (!this.showing) {
return;
}
this.showing = false;
var removed = this.viewSlot.remove(this.view);
if (removed instanceof Promise) {
return removed.then(function () {
return _this.view.unbind();
});
}
this.view.unbind();
};
return IfCore;
}();