Skip to content

Instantly share code, notes, and snippets.

@vemarav
Forked from mactive/debuggerWorker.js
Created May 2, 2018 07:15
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 vemarav/e497b0e329333ccb4f037090065be415 to your computer and use it in GitHub Desktop.
Save vemarav/e497b0e329333ccb4f037090065be415 to your computer and use it in GitHub Desktop.
// file location:
// node_modules/react-native/local-cli/server/util/debuggerWorker.js
var messageHandlers = {
'executeApplicationScript': function(message, sendReply) {
for (var key in message.inject) {
self[key] = JSON.parse(message.inject[key]);
}
importScripts(message.url);
sendReply();
}
};
onmessage = function(message) {
var object = message.data;
var sendReply = function(result) {
postMessage({replyID: object.id, result: result});
};
var handler = messageHandlers[object.method];
if (handler) {
// Special cased handlers
handler(object, sendReply);
} else {
// Other methods get called on the bridge
var returnValue = [[], [], [], [], []];
try {
if (typeof __fbBatchedBridge === 'object') {
returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
}
} finally {
sendReply(JSON.stringify(returnValue));
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment