1.2.1 • Published 26 days ago

commutator v1.2.1

Weekly downloads
-
License
-
Repository
github
Last release
26 days ago

Commutator

Making RPC calls (asynchronous method calls) between browser windows or iframes.

Install

npm install commutator

Usage

parent.js

import { Commutator } from 'commutator';

const rpc = new Commutator({
  // The window you want to talk to:
  target: myIframe.contentWindow,
  // This should be unique for each of your producer<->consumer pairs:
  serviceId: 'my-awesome-service',
});

rpc.expose('add', (data) => data.a + data.b);

Destroy the instance

rpc.destroy();

Remove expose handler

const handleAdd = (data) => data.a + data.b
// Expose
rpc.expose('add', handleAdd);
// Unexpose
rpc.unexpose('add', handleAdd);

iframe.js

import { Commutator } from 'commutator';

const rpc = new Commutator({
  target: window.parent,
  serviceId: 'my-awesome-service',
});

rpc.call('add', { a: 3, b: 5 }).then(result => console.log('3 + 5 is', result));
1.2.0

26 days ago

1.2.1

26 days ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago