-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket-on.html
49 lines (44 loc) · 1.09 KB
/
socket-on.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
<link rel="import" href="../polymer/polymer.html">
<dom-module id="socket-on">
<template>
</template>
<script>
/**
* The `socket-on` element builds off of a connection that was set up using `<socket-connect>`.
*
* It will handle any event that occurs with the provided name and return the data sent via
* the data attribute
*
* Example:
*
* <socket-on name="demo" data="{{receivedata}}"></socket-on>
*
* @demo demo/index.html
*/
Polymer({
is: 'socket-on',
properties: {
/**
* `name` is the name of the event to handle
*/
name: String,
/**
* `data` represents the provided data with the socket event
*/
data: {
type: Object,
notify: true,
reflectToAttribute: true
}
},
/**
* Sets up the socket.on event handler
*/
_setup: function(socket, token){
socket.on(this.name, function(data){
this.data = data;
}.bind(this));
}
});
</script>
</dom-module>