-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
49 lines (44 loc) · 1.28 KB
/
example.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
if (Meteor.isClient) {
// counter_factory component
Component.define(Template.counter_factory, {
created: function () {
this.shared = new ReactiveDict();
this.shared.set('counter', 40);
},
helpers: {
length:function () {
return this.shared.get('counter');
}
},
events: {
'click [data-standalone]': function () {
Blaze.renderWithData(Template.counter, {}, document.body);
},
'click [data-shared]': function () {
Blaze.renderWithData(Template.counter, {sharedCount:this.shared}, document.body);
}
}
});
// counter component (counter data can be standalone or shared with other components)
Component.define(Template.counter, {
created: function () {
var self = this;
// use shared counter if available
if (Template.instance().data && Template.instance().data.sharedCount)
self.state = Template.instance().data.sharedCount;
else
self.state.set("counter", 0);
},
helpers: {
counter: function () {
return this.state.get("counter");
}
},
events: {
'click button': function () {
// increment the counter when button is clicked
this.state.set("counter", this.state.get("counter") + 1);
}
}
});
}