-
Notifications
You must be signed in to change notification settings - Fork 3
/
meteor-session.html
44 lines (39 loc) · 916 Bytes
/
meteor-session.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
<!--
A wrapper to meteor Session object.
Example :
<meteor-session name="mainPanelIsActivated" value="{{isMainPanelIsActivated}}"></meteor-session>
<div hidden$="{{isMainPanelIsActivated}}">
...
</div>
-->
<script>
Polymer({
is: 'meteor-session',
properties: {
name: {
type: String,
observer : '_nameChanged'
},
result: {
type: Object,
notify : true,
observer : '_resultChanged'
}
},
_nameChanged : function() {
if (this._computation)
this._computation.stop();
this._computation = Tracker.autorun(function() {
this.result = Session.get(this.name);
}.bind(this));
},
_resultChanged : function(newValue, oldValue) {
if(!EJSON.equals(oldValue,newValue))
Session.set(this.name, newValue);
},
detached: function() {
if (this._computation)
this._computation.stop();
},
});
</script>