Ну, это скорее javascript, чем вопрос об электронах.
У меня есть следующий код:
var electron = require("electron")
var registerTestHandler = function(onFn) {
onFn("test", console.log)
}
electron.app.whenReady()
.then(function() {
registerTestHandler(electron.ipcMain.on)
})
При запуске приложения выдается следующая ошибка:
(node:14139) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_events' of undefined
at _addListener (events.js:228:19)
at addListener (events.js:284:10)
at registerTestHandler (/Users/marco/Desktop/electron-ipc-test/index.js:4:2)
at /Users/marco/Desktop/electron-ipc-test/index.js:9:2
(node:14139) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_events' of undefined
at _addListener (events.js:228:19)
at addListener (events.js:284:10)
at registerTestHandler (/Users/marco/Desktop/electron-ipc-test/index.js:4:2)
at /Users/marco/Desktop/electron-ipc-test/index.js:9:2
(node:14139) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14139) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14139) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:14139) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Теперь изменив код на:
var electron = require("electron")
var registerTestHandler = function(ipc) {
ipc.on("test", console.log)
}
electron.app.whenReady()
.then(function() {
registerTestHandler(electron.ipcMain)
})
И все работает отлично!
Я не думаю, что это имеет какое-либо отношение к электрону, а скорее к javascript.
Однако я не могу объяснить, почему это происходит.
Кто-нибудь есть идея?