Event model

Ice Sickle is an event-driven application. The app.js file is fundamental code to launch the app, but it is the windows, along with their communication with the app, that drives the development of a project.

During the course of using Ice Sickle to develop a project, many different types of events are sent out by the app. Windows can listen to these events to respond to key actions, such as the project being saved, or a unit being placed on the map. Additionally, windows can send requests to the app to modify the project.

Where can I find the events the application uses? On the Events reference page.

Using ipcRenderer to send and listen

In order to build windows and add or improve functionality of the app, it is important to know how to send requests and respond to events. This section is designed to familiarize you with these matters. Below is some sample code to illustrate these two concepts:

// Sample code illustrating events
var {ipcRenderer} = require('electron'),
    Map;

ipcRenderer.send('request-project');
ipcRenderer.on('response-project', function(a, map) {
    Map = map;
})

First, the ipcRenderer is imported. This is how you'll send requests and listen for events. It is therefore very important that you follow the syntax listed on the first line exactly. The ipcRenderer has two methods shown here: send and on. From the example, its simple to see what they do, but here are some details.

send Send the specified event to the app, with optional data as a 2nd argument.

on Listen (subscribe) to the specified event name, and specify a callback function that is called with the event and response data. This callback is called, allowing us to perform tasks with the data.

In the example above, the following three things occur:

  1. Import the ipcRenderer to work with events
  2. Send a request to the app, named request-project
  3. Subscribe to the response-project event

results matching ""

    No results matching ""