From 35a4098b82873994df0128582ccc4e74717457f9 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 30 Dec 2017 20:57:40 -0500 Subject: [PATCH] move js code to its own folder --- lib/modules/whisper/index.js | 5 +++-- lib/modules/whisper/{ => js}/embarkjs.js | 21 ++----------------- .../whisper/{ => js}/embarkjs_old_web3.js | 20 ++---------------- lib/modules/whisper/js/message_events.js | 17 +++++++++++++++ 4 files changed, 24 insertions(+), 39 deletions(-) rename lib/modules/whisper/{ => js}/embarkjs.js (86%) rename lib/modules/whisper/{ => js}/embarkjs_old_web3.js (87%) create mode 100644 lib/modules/whisper/js/message_events.js diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index d1a3b80f0..9fdef066d 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -42,12 +42,13 @@ class Whisper { // TODO: possible race condition could be a concern this.events.request("version:get:web3", function(web3Version) { let code = ""; + code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString(); if (web3Version[0] === "0") { - code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs_old_web3.js')).toString(); + code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs_old_web3.js')).toString(); code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperOld);"; } else { - code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString(); + code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs.js')).toString(); code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperNewWeb3);"; } self.embark.addCodeToEmbarkJS(code); diff --git a/lib/modules/whisper/embarkjs.js b/lib/modules/whisper/js/embarkjs.js similarity index 86% rename from lib/modules/whisper/embarkjs.js rename to lib/modules/whisper/js/embarkjs.js index 2199bb06f..38e0a95b4 100644 --- a/lib/modules/whisper/embarkjs.js +++ b/lib/modules/whisper/js/embarkjs.js @@ -60,26 +60,9 @@ __embarkWhisperNewWeb3.sendMessage = function(options) { }; __embarkWhisperNewWeb3.listenTo = function(options) { - var topics, messageEvents; - messageEvents = function() { - this.cb = function() {}; - }; + var topics = options.topic || options.topics; - messageEvents.prototype.then = function(cb) { - this.cb = cb; - }; - - messageEvents.prototype.error = function(err) { - return err; - }; - - messageEvents.prototype.stop = function() { - this.filter.stopWatching(); - }; - - topics = options.topic || options.topics; - - let promise = new messageEvents(); + let promise = new __MessageEvents(); if (typeof topics === 'string') { topics = [this.web3.utils.toHex(topics).slice(0, 10)]; diff --git a/lib/modules/whisper/embarkjs_old_web3.js b/lib/modules/whisper/js/embarkjs_old_web3.js similarity index 87% rename from lib/modules/whisper/embarkjs_old_web3.js rename to lib/modules/whisper/js/embarkjs_old_web3.js index c2f52a4cf..51ac2220a 100644 --- a/lib/modules/whisper/embarkjs_old_web3.js +++ b/lib/modules/whisper/js/embarkjs_old_web3.js @@ -63,26 +63,10 @@ __embarkWhisperOld.sendMessage = function(options) { }; __embarkWhisperOld.listenTo = function(options) { - var topics, _topics, messageEvents; + var topics, _topics; topics = options.topic || options.topics; _topics = []; - messageEvents = function() { - this.cb = function() {}; - }; - - messageEvents.prototype.then = function(cb) { - this.cb = cb; - }; - - messageEvents.prototype.error = function(err) { - return err; - }; - - messageEvents.prototype.stop = function() { - this.filter.stopWatching(); - }; - if (typeof topics === 'string') { _topics = [topics]; } else { @@ -94,7 +78,7 @@ __embarkWhisperOld.listenTo = function(options) { topics: topics }; - let promise = new messageEvents(); + let promise = new __MessageEvents(); let filter = this.web3.shh.filter(filterOptions, function(err, result) { var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload)); diff --git a/lib/modules/whisper/js/message_events.js b/lib/modules/whisper/js/message_events.js new file mode 100644 index 000000000..0205d8b22 --- /dev/null +++ b/lib/modules/whisper/js/message_events.js @@ -0,0 +1,17 @@ + +var __MessageEvents = function() { + this.cb = function() {}; +}; + +__MessageEvents.prototype.then = function(cb) { + this.cb = cb; +}; + +__MessageEvents.prototype.error = function(err) { + return err; +}; + +__MessageEvents.prototype.stop = function() { + this.filter.stopWatching(); +}; +