Skip to content

Instantly share code, notes, and snippets.

@dougblackjr
Created March 8, 2019 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dougblackjr/b2dccddb526623333f15d3b5975896de to your computer and use it in GitHub Desktop.
Save dougblackjr/b2dccddb526623333f15d3b5975896de to your computer and use it in GitHub Desktop.
SPY: Spies user interactions for sending back to server, or dumping to browser
var Spy = (function (register, undefined) {
var eventStore = [],
events = ['click'];
var store = function (type, data) {
eventStore.push({
type: type,
data: data
});
};
events.forEach(function (event) {
register(event, function (data) {
store(event, data);
}, false);
});
return {
dump: function () {
console.log(eventStore);
},
store: function () {
// do whatever you wanna do here…
},
send: function() {
// @TODO: Create websocket/server call to send back
}
};
})(document.addEventListener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment