An element used to communicate through the ipc
module for electron. It can
send or receive data from a single or multiple events at once.
By default the element will send data to the specified events whenever it's
required to do so, or it automatically send the data if auto
is set.
<electron-ipc id="target" events="myEvent" data="myData"></electron-ipc>
<script>
document.querySelector('#target').send();
</script>
<electron-ipc events="myEvent" data="myData" auto></electron-ipc>
If you need to listen to events instead of sending them, just transform the
element into a receiver
and it will keep data
up to date whenever it
receives new information.
<electron-ipc id="target" receiver></electron-ipc>
<script>
var el = document.querySelector('#target');
el.events = ['firstEvent', 'secondEvent'];
/**
* From the main process:
* ipc.send('firstEvent', 'Hello!');
*/
console.log(el.data); // 'Hello!'
/**
* From the main process:
* ipc.fire('secondEvent', 'World!');
*/
console.log(el.data); // 'World!'
</script>
Default: false
If set to true
a the element will automatically send a message when data
is changed.
The element's data, either received from events or set by the user.
The events associated to the element, either for listening or sending messages.
Default: false
If set to true
the element becomes a receiver
and is able to receive messages.
Fired when data is received through ipc.
Detail:
- firer {Element} The element itself
- data {*} The data received
- event {string} The name of the event that generated the event
Fired when data is sent through ipc.
Detail:
- firer {Element} The element itself.
- data {*} The data sent.
- event {string} The name of the event that generated the event.
Sends an ipc message using data. If no data is passed then the data
set on the element will be sent.
Parameters:
- [data] {*} Optional data to be sent.