computers
Version:
computer←→computer
49 lines (37 loc) • 799 B
Markdown
<div align="center">
<img src="./doc/computers.png" />
<h1><code>computers</code></h1>
<h3>type-safe bi-directional communication library</h3>
</div>
```
bun i computers
```
```ts
// In your browser
import {web} from 'computers/web';
import type {api} from './frame.ts';
const iframe = document.querySelector('iframe');
const client = web<api>({
self: window,
target: frame.contentWindow,
});
client.add(10, 20);
```
```ts
// In your frame.ts (which the iframe loads somehow)
import {web} from 'computers/web';
const api = {
add: (a: number, b: number) => a + b,
};
export type api = typeof api;
web(
{
self: window,
target: window.parent,
},
api, // Pass `api` as a second argument to expose it
);
```
This is a project by @aidenybai & @alii