Skip to content

Commit

Permalink
Closes #149 - websocket onmessage use zones to capture async behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
James Atherton committed Nov 6, 2017
1 parent 012cb5b commit d7d91d1
Show file tree
Hide file tree
Showing 4 changed files with 7,003 additions and 5 deletions.
20 changes: 20 additions & 0 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,23 @@ exports.removeEventListener = function(removeEventListener){
return removeEventListener.call(this, eventName, outHandler, useCapture);
};
};

exports.WebSocket = function (WebSocket) {
return function (url, protocols) {
var ws = new WebSocket(url, protocols);
var onmessageSet;
var onmessage = CanZone.current.wrap(function (ev) {
return onmessageSet && onmessageSet.call(ws, ev);
});
ws.onmessage = onmessage;
Object.defineProperty(ws, "onmessage", {
get: function () {
return onmessageSet;
},
set: function (fnVal) {
onmessageSet = fnVal;
}
})
return ws;
}
}
Loading

0 comments on commit d7d91d1

Please sign in to comment.