Skip to content

Commit

Permalink
refactor parsing of events received from hippie server into a method
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Apr 23, 2013
1 parent 4f99f0e commit edecfaf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions share/hippie.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ var Hippie = function(opt) {
that.host = document.location.protocol.replace(/http/, 'ws') + '//' + that.host;
that.ws = new WebSocket(that.host+that.path+"/_hippie/ws/"+that.arg + that.params);
that.ws.onmessage = function(ev) {
var d;
try {
d = eval("("+ev.data+")");
} catch(ex) {
d = ev.data;
};
that.on_event(d);
that.data_received(ev);
}
that.ws.onclose = that.ws.onerror = function(ev) {
that.on_disconnect();
Expand All @@ -57,8 +51,7 @@ var Hippie = function(opt) {
// reconnect introduces duplicated listeners.
that.mxhr.listeners = {};
that.mxhr.listen('application/json', function(payload) {
var d = eval('(' + payload + ')');
that.on_event(d);
that.data_received(payload);
});
that.mxhr.listen('complete', function() {
that.on_disconnect();
Expand All @@ -83,6 +76,15 @@ var Hippie = function(opt) {
};

Hippie.prototype = {
data_received: function(ev) {
var d;
try {
d = eval("("+ev.data+")");
} catch(ex) {
d = ev.data;
};
this.on_event(d);
},
set_params: function(params) {
this.params = params;
if (this.mode == 'poll') {
Expand Down

0 comments on commit edecfaf

Please sign in to comment.