-
Notifications
You must be signed in to change notification settings - Fork 3
/
meteor-call.html
67 lines (61 loc) · 1.21 KB
/
meteor-call.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
<!--
A wrapper to meteor Method.call.
Example :
<meteor-call name="getscore" args="[100, 200]" result={{players}}></meteor-call>
<template is="dom-repeat" items="{{players}}">
<div>
<span>{{item.name}}</span>
</div>
</template>
-->
<script>
Polymer({
is: 'meteor-call',
/**
* Fired when call has result
* @param {object} result
* @event result
*/
/**
* Fired when call has response error
* @param {object} error
* @event error
*/
properties: {
/**
* Meteor method name to call.
*/
name: {
type: String,
value: ""
},
/**
* An array of Optional method arguments
*/
args: {
type: Array,
value: function() { return []; }
},
/**
* Result of last call
*/
result: {
type: Object,
notify : true
},
},
observers: [ '_recall(name, args)' ],
_recall : function(name , args) {
if(name) {
Meteor.apply(name, args, function (error, result) {
if(error) {
this.fire('error', {error: error});
} else {
this.result = result;
this.fire('result', {result: result});
}
}.bind(this));
}
}
});
</script>