Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sasaplus1/ipc-promise

ipc use as Promises
https://github.com/sasaplus1/ipc-promise

electron ipc javascript library promise

Last synced: 6 days ago
JSON representation

ipc use as Promises

Awesome Lists containing this project

README

        

# ipc-promise

[![Build Status](https://travis-ci.org/sasaplus1/ipc-promise.svg)](https://travis-ci.org/sasaplus1/ipc-promise)
[![Dependency Status](https://gemnasium.com/sasaplus1/ipc-promise.svg)](https://gemnasium.com/sasaplus1/ipc-promise)
[![NPM version](https://badge.fury.io/js/ipc-promise.svg)](http://badge.fury.io/js/ipc-promise)

ipc use as Promises

## Installation

### npm

```sh
$ npm install ipc-promise
```

## Usage

### main process

```js
var ipcPromise = require('ipc-promise');

ipcPromise.on('twice', function(params) {
return Promise.resolve(params.value * 2);
});

var electron = require('electron'),
app = electron.app,
BrowserWindow = electron.BrowserWindow,
mainWindow;

app.on('ready', function() {
mainWindow = new BrowserWindow({});
mainWindow.loadURL('file://' + __dirname + '/index.html');
});
```

### renderer process

```html

ipcPromise
.send('twice', {
value: 1
})
.then(function(result) {
console.log(result); // => "2"
});

```

## Functions

### on(event, listener)

- `event`
- `String` - event name
- `listener`
- `Function(*): Promise` - listener function

listen event.

### send(event, data)

- `event`
- `String` - event name
- `data`
- `*` - data for send
- `return`
- `Promise` - Promises

trigger event.

## Test

```sh
$ npm install
$ npm test
```

## License

The MIT license. Please see LICENSE file.