GitXplorerGitXplorer
k

comlink-electron-adapter

public
6 stars
1 forks
0 issues

Commits

List of commits on branch master.
Verified
3c0d331986a22e0949e0f22dd06eb0671501474f

Merge pull request #7 from kwonoj/release-0.0.1

kkwonoj committed 6 years ago
Verified
9c48391be9c7676e40d1689923a214660d31c110

build(release): release 0.0.1

kkwonoj committed 6 years ago
Verified
68f05969b1be8bebcb35a360833174fabd843504

build(package): update scripts

kkwonoj committed 6 years ago
Verified
b9642a0ffe849a0e56c6a9da0dc52a9a387a4901

Merge pull request #6 from kwonoj/fix-docs

kkwonoj committed 6 years ago
Verified
9c31e20c49ff3757e36d9bb592de7b1598efcd50

docs(readme): update documentation

kkwonoj committed 6 years ago
Verified
1a7728ba2eb7f29b260da53d7bdeca381b3b7c78

Merge pull request #5 from kwonoj/docs-readme

kkwonoj committed 6 years ago

README

The README file for this repository.

Build Status Build status codecov npm node

Comlink-electron-adapter

Comlink provides way to interface between worker-like endpoint via ES proxy. This module allows to create custom endpoints around Electron's IPC (https://electronjs.org/docs/api/ipc-main) for proxy object across Electron's processes.

Install

This has a peer dependencies of comlink@4, which will have to be installed as well

npm install comlink-electron-adapter

Usage

There are separate endpoint creation method per object's origin.

Expose main process's object to renderer project

// main process
import { ipcMain } from 'electron';
import { expose } from 'comlink';
import { mainProcObjectEndpoint } from 'comlink-electron-adapter';

const mainProcessObject = {...};
expose(mainProcessObject, mainProcObjectEndpoint(ipcMain));

// renderer process
import { wrap } from 'comlink';
import { ipcRenderer } from 'electron';

// `proxied` is proxy object to `mainProcessObject` in main process
const proxied = wrap(mainProcObjectEndpoint(ipcRenderer));

Expose renderer process's object to main process

It is also possible to access renderer process's object in main process.

// renderer process
import { expose } from 'comlink';
import { ipcRenderer } from 'electron';
import { rendererProcObjectEndpoint } from 'comlink-electron-adapter';

const rendererProcessObject = {...};
expose(rendererProcessObject, rendererProcObjectEndpoint(ipcRenderer));

// main process
import { wrap } from 'comlink';
import { ipcMain } from 'electron';
import { rendererProcObjectEndpoint } from 'comlink-electron-adapter';

const rendererProcessWindow = new BrowserWindow();
rendererProcessWindow.loadFile('.../renderer.js');

const proxied = wrap(requestRendererProcessEndpoint(ipcMain, rendererProcessWindow.webContents));

Unlike renderer process main process does not aware target renderer process to send message and target webContents should be specified. Also main process should wait call proxy object until renderer process expose its object.

Note

Due to Electron IPC's design comlink-electron-adapter do not support transferable. Using Comlink.transfer will raise not supported exception.

Building / Testing

Few npm scripts are supported for build / test code.

  • build: Transpiles code to ES5 commonjs to dist.
  • test: Run test cases.
  • lint: Run lint over all codebases
  • lint:staged: Run lint only for staged changes. This'll be executed automatically with precommit hook.
  • commit: Commit wizard to write commit message

License

MIT