-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta4-state.html
57 lines (50 loc) · 1.24 KB
/
meta4-state.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
<link rel="import" href="/bower_components/polymer/polymer.html">
<dom-module id="meta4-state">
<script>
(function() {
var instances = [];
var vars = Object.create(Polymer.Base);
Polymer({
is: 'meta4-state',
properties: {
data: {
type: Object,
value: '',
notify: true,
readonly: false,
observer: '_data_changed'
},
key: String
},
created: function() {
key = this.getAttribute('key');
if (!key) {
console.log(this);
throw('app-data element requires key');
}
instances.push({key:key, instance:this});
},
detached: function() {
key = this.getAttribute('key');
var i = instances.indexOf({key:key, instance:this});
if (i >= 0) {
instances.splice(i, 1);
}
},
_data_changed: function(newvalue, oldvalue) {
key = this.getAttribute('key');
if (!key) {
throw('_data_changed: app-data element requires key');
}
vars.set(key, newvalue);
// notify the instances with the correct key
for (var i = 0; i < instances.length; i++) {
if (instances[i].key == key) {
instances[i].instance.notifyPath('data', newvalue);
}
}
}
});
}());
</script>
</dom-module>