-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.ts
51 lines (47 loc) · 1.3 KB
/
readme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* cycle-classic-dom
* -------------------
*
* A tiny helper library for working with classic JS libraries.
*
* That is to say, any JS library that works by taking a reference
* to an element and manipulating the DOM directly.
*
* `npm install cycle-classic-dom`
*/
import { div, VNode } from "@cycle/dom";
import { Stream } from "xstream";
export type Constructor = (el: HTMLElement) => void;
export function makeVNode(ctor: Constructor): VNode {
return div({
key: Math.random().toString(),
hook: { insert: vnode => ctor(vnode.elm) }
});
}
/**
* Example, sets up a simple xterm.js powered terminal:
*
* import { makeVNode } from 'cycle-classic-dom';
* import { makeDOMDriver } from '@cycle/dom';
* import { Terminal } from 'xterm'
* import xs from 'xstream';
*
* function main() {
* const terminal = new Terminal();
*
* terminal.write("Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ");
*
* const terminalVNode = makeVNode(element => {
* terminal.open(element);
* terminal.refresh(0, terminal.rows - 1);
* });
*
* return {
* DOM: xs.of(terminalVNode)
* }
* }
*
* run(main, {DOM: makeDOMDriver(document.body)});
*
* For a larger example including capturing output, see the example directory
*/