electron/atom/renderer/api/lib/ipc.js

33 lines
959 B
JavaScript
Raw Normal View History

2016-01-12 02:40:23 +00:00
var EventEmitter, deprecate, ipc, ipcRenderer, method, ref,
slice = [].slice;
ref = require('electron'), ipcRenderer = ref.ipcRenderer, deprecate = ref.deprecate;
EventEmitter = require('events').EventEmitter;
2016-01-14 18:35:29 +00:00
// This module is deprecated, we mirror everything from ipcRenderer.
2016-01-12 02:40:23 +00:00
deprecate.warn('ipc module', 'require("electron").ipcRenderer');
2016-01-14 18:35:29 +00:00
// Routes events of ipcRenderer.
2016-01-12 02:40:23 +00:00
ipc = new EventEmitter;
ipcRenderer.emit = function() {
var args, channel, event;
channel = arguments[0], event = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
ipc.emit.apply(ipc, [channel].concat(slice.call(args)));
return EventEmitter.prototype.emit.apply(ipcRenderer, arguments);
};
2016-01-14 18:35:29 +00:00
// Deprecated.
2016-01-12 02:40:23 +00:00
for (method in ipcRenderer) {
if (method.startsWith('send')) {
ipc[method] = ipcRenderer[method];
}
}
deprecate.rename(ipc, 'sendChannel', 'send');
deprecate.rename(ipc, 'sendChannelSync', 'sendSync');
module.exports = ipc;