mirror of https://github.com/embarklabs/embark.git
enable events calling for request and on
This commit is contained in:
parent
953ce6659e
commit
1ffc9ffe08
|
@ -72,6 +72,7 @@ class Pipeline {
|
|||
const webpackProcess = new ProcessLauncher({
|
||||
modulePath: utils.joinPath(__dirname, 'webpackProcess.js'),
|
||||
logger: self.logger,
|
||||
events: self.events,
|
||||
normalizeInput: self.normalizeInput
|
||||
});
|
||||
webpackProcess.send({action: constants.pipeline.init, options: {}});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
const uuid = require('uuid/v1');
|
||||
const constants = require('../constants');
|
||||
|
||||
class Events {
|
||||
constructor() {
|
||||
this.eventId = 0;
|
||||
this.subscribedEvents = {};
|
||||
this.listenToParentProcess();
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ class Events {
|
|||
const requestName = arguments[1];
|
||||
|
||||
let args = [].slice.call(arguments, 2);
|
||||
this.eventId++;
|
||||
this.subscribedEvents[this.eventId] = args[args.length - 1];
|
||||
const eventId = uuid();
|
||||
this.subscribedEvents[eventId] = args[args.length - 1];
|
||||
args = args.splice(0, args.length - 2);
|
||||
|
||||
process.send({
|
||||
event: eventType,
|
||||
requestName,
|
||||
args,
|
||||
eventId: this.eventId
|
||||
eventId: eventId
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ class ProcessLauncher {
|
|||
this.process = child_process.fork(options.modulePath);
|
||||
this.logger = options.logger;
|
||||
this.normalizeInput = options.normalizeInput;
|
||||
this.events = options.events;
|
||||
|
||||
this.subscriptions = {};
|
||||
this._subscribeToMessages();
|
||||
|
@ -32,7 +33,23 @@ class ProcessLauncher {
|
|||
}
|
||||
|
||||
_handleEvent(msg) {
|
||||
console.log(msg);
|
||||
const self = this;
|
||||
if (!self.events[msg.event]) {
|
||||
self.logger.warn('Unknown event method called: ' + msg.event);
|
||||
return;
|
||||
}
|
||||
if (!msg.args || !Array.isArray(msg.args)) {
|
||||
msg.args = [];
|
||||
}
|
||||
// Add callback in the args
|
||||
msg.args.push((result) => {
|
||||
self.process.send({
|
||||
event: constants.process.events.response,
|
||||
result,
|
||||
eventId: msg.eventId
|
||||
});
|
||||
});
|
||||
self.events[msg.event](msg.requestName, ...msg.args);
|
||||
}
|
||||
|
||||
_checkSubscriptions(msg) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const constants = require('../constants');
|
||||
const Events = require('./eventsWrapper');
|
||||
|
||||
// Override process.chdir so that we have a partial-implementation PWD for Windows
|
||||
const realChdir = process.chdir;
|
||||
|
@ -12,6 +13,7 @@ process.chdir = (...args) => {
|
|||
class ProcessWrapper {
|
||||
constructor(_options) {
|
||||
this.interceptLogs();
|
||||
this.events = new Events();
|
||||
}
|
||||
|
||||
interceptLogs() {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.2.tgz",
|
||||
"integrity": "sha512-Q3FWsbdmkQd1ib11A4XNWQvRD//5KpPoGawA8aB2DR7pWKoW9XQv3+dGxD/Z1eVFze23Okdo27ZQytVFlweKvQ==",
|
||||
"requires": {
|
||||
"@types/node": "10.0.9"
|
||||
"@types/node": "10.1.0"
|
||||
}
|
||||
},
|
||||
"@types/lockfile": {
|
||||
|
@ -32,16 +32,16 @@
|
|||
"integrity": "sha512-pD6JuijPmrfi84qF3/TzGQ7zi0QIX+d7ZdetD6jUA6cp+IsCzAquXZfi5viesew+pfpOTIdAVKuh1SHA7KeKzg=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "10.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.0.9.tgz",
|
||||
"integrity": "sha512-ekJ3mXJcJP+Nn5kC6eCmWPND/fHx/Ga12Lz0IJgTfGz1ge7OCIR5xcDY5tcYgnyM1kWsVDRH2bguxkGcNj39AQ=="
|
||||
"version": "10.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.1.0.tgz",
|
||||
"integrity": "sha512-sELcX/cJHwRp8kn4hYSvBxKGJ+ubl3MvS8VJQe5gz/sp7CifYxsiCxIJ35wMIYyGVMgfO2AzRa8UcVReAcJRlw=="
|
||||
},
|
||||
"@types/node-fetch": {
|
||||
"version": "1.6.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-1.6.9.tgz",
|
||||
"integrity": "sha512-n2r6WLoY7+uuPT7pnEtKJCmPUGyJ+cbyBR8Avnu4+m1nzz7DwBVuyIvvlBzCZ/nrpC7rIgb3D6pNavL7rFEa9g==",
|
||||
"requires": {
|
||||
"@types/node": "10.0.9"
|
||||
"@types/node": "10.1.0"
|
||||
}
|
||||
},
|
||||
"@types/semver": {
|
||||
|
@ -54,7 +54,7 @@
|
|||
"resolved": "https://registry.npmjs.org/@types/tar/-/tar-4.0.0.tgz",
|
||||
"integrity": "sha512-YybbEHNngcHlIWVCYsoj7Oo1JU9JqONuAlt1LlTH/lmL8BMhbzdFUgReY87a05rY1j8mfK47Del+TCkaLAXwLw==",
|
||||
"requires": {
|
||||
"@types/node": "10.0.9"
|
||||
"@types/node": "10.1.0"
|
||||
}
|
||||
},
|
||||
"@types/url-join": {
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"underscore": "^1.9.0",
|
||||
"underscore.string": "^3.3.4",
|
||||
"url-loader": "^0.6.2",
|
||||
"uuid": "^3.2.1",
|
||||
"viz.js": "^1.8.1",
|
||||
"web3": "1.0.0-beta.34",
|
||||
"web3-provider-engine": "^14.0.5",
|
||||
|
|
Loading…
Reference in New Issue