forked from Neovici/cosmoz-omnitable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmoz-omnitable-templatizer.html
123 lines (96 loc) · 2.71 KB
/
cosmoz-omnitable-templatizer.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<link rel="import" href="../polymer/polymer.html">
<script>
(function () {
'use strict';
const IS_V2 = Polymer.flush != null;
Polymer({
is: 'cosmoz-omnitable-templatizer',
behaviors: [
Polymer.Templatizer
],
_templateInstancesInUse: null,
_reusableTemplateInstances: null,
_parentModel: true,
ready: function () {
var instanceProps = {};
instanceProps['item'] = true;
this._instanceProps = instanceProps;
this._templateInstancesInUse = [];
this._reusableTemplateInstances = [];
},
init: function (template, host) {
this._template = template;
this._templateHost = host;
this.dataHost = host;
},
_getRootDataHost: function () {
return this._templateHost;
},
_ensureTemplatized: function () {
if (!this.ctor) {
this.templatize(this._template);
}
},
_forwardParentProp: function (prop, value) {
const set = instance => {
instance[prop] = value;
};
this._templateInstancesInUse.forEach(set);
this._reusableTemplateInstances.forEach(set);
},
_forwardParentPath: function (path, value) {
const notify = instance => {
instance.notifyPath(path, value, true);
};
this._templateInstancesInUse.forEach(notify);
this._reusableTemplateInstances.forEach(notify);
},
_forwardHostPropV2: function (prop, value) {
const forward = instance => {
instance.forwardHostProp(prop, value);
};
this._templateInstancesInUse.forEach(forward);
this._reusableTemplateInstances.forEach(forward);
},
getInstance: function () {
var instance;
if (this._reusableTemplateInstances.length > 0) {
instance = this._performInstanceDetach(this._reusableTemplateInstances.pop());
} else {
this._ensureTemplatized();
instance = this.stamp(IS_V2 ? null : {});
}
this._templateInstancesInUse.push(instance);
instance.__detached__ = false;
return instance;
},
detachInstance: function (instance) {
this.releaseInstance(instance);
this._performInstanceDetach(instance);
},
releaseInstance: function (instance) {
const index = this._templateInstancesInUse.indexOf(instance);
if (index < 0) {
return;
}
this._templateInstancesInUse.splice(index, 1);
this._reusableTemplateInstances.push(instance);
},
releaseInstances: function () {
this._reusableTemplateInstances = this._templateInstancesInUse;
this._templateInstancesInUse = [];
},
_performInstanceDetach(instance) {
if (instance.__detached__) {
return instance;
}
const children = IS_V2 ? instance.children : instance._children;
for (let i = 0; i < children.length; i++) {
Polymer.dom(instance.root).appendChild(children[i]);
}
instance.__detached__ = true;
return instance;
}
});
}());
</script>