最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to send several arguments with ipcRenderer - Stack Overflow

programmeradmin4浏览0评论

I'd like to know how to send several arguments via ipcRenderer on an Electron app. Should I send an array of arguments or just all the arguments separated by comma?

Thanks,

I'd like to know how to send several arguments via ipcRenderer on an Electron app. Should I send an array of arguments or just all the arguments separated by comma?

Thanks,

Share Improve this question asked Aug 12, 2018 at 3:13 Otto GutierrezOtto Gutierrez 4872 gold badges7 silver badges15 bronze badges 2
  • 1 I can see the benefit of both, using an object and passing multiple arguments. However, I would lean more towards passing an object (or even multiple objects as arguments) as it would more closely follow general development guidelines of using data transfer objects. – user3268346 Commented Mar 14, 2019 at 4:55
  • Yes, that is what I ended up doing. Personally I like it better this way, since it becomes much simpler to organized your data once received on the other side. Thanks for your comment! – Otto Gutierrez Commented Mar 27, 2019 at 19:29
Add a comment  | 

3 Answers 3

Reset to default 13

I would recommend an object for parameter transfer. In consequence, you can also think about implementing a consistent API for your application:

var _myreq = {
  state: 0, //0 is no error, 4 is error with message, etc.
  message: "", //can include error message (if any)
  data: [0,4,6] //application data for request (String, Array, Object)
};
ipc.send('mychannel-functiona', _myreq);

Docs clearly shows that you can pass any number of argument to send.

Send a message to the main process asynchronously via channel, you can also send arbitrary arguments. Arguments will be serialized in JSON internally and hence no functions or prototype chain will be included.

From that point on you have no restrictions on how to use those arbitrary arguments. It depends on your needs, your codebase style etc.

We can pass many arguments for the ipcRenderer, you can refer this page: https://electronjs.org/docs/api/ipc-renderer.

发布评论

评论列表(0)

  1. 暂无评论