-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.ts
74 lines (65 loc) · 1.52 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Observable } from 'rxjs';
import { run } from '@cycle/rxjs-run';
import {
ul,
li,
div,
h3,
p,
makeDOMDriver,
DOMSource,
VNode
} from '@cycle/dom';
import { makeSortable } from '../../../src/makeSortable';
interface Sources {
DOM: DOMSource;
}
interface Sinks {
DOM?: Observable<VNode>;
drag?: Observable<boolean>;
}
function userSelectDriver(sort$): void {
sort$.addListener({
next(b) {
if (b) {
document.body.setAttribute(
'style',
'-webkit-user-select: none; -moz-user-select: none;' +
' -ms-user-select: none; user-select: none;'
);
} else {
document.body.removeAttribute('style');
}
}
});
}
function main(sources: Sources): Sinks {
const sinks: any = makeSortable(Child, {
itemSelector: 'ul > li'
})(sources);
return {
drag: sinks.dragging,
DOM: sinks.DOM.map(dom =>
div([h3('Horizontal too!'), p('this is running with RxJS'), dom])
)
};
}
function Child({ DOM }: Sources): Sinks {
const vdom$: Observable<VNode> = Observable.of(
ul([
li(['Option 1']),
li(['Option 2']),
li(['Option 3']),
li(['Option 4']),
li(['Option 5']),
li(['Option 6'])
])
);
return {
DOM: vdom$
};
}
run(main, {
DOM: makeDOMDriver('#app'),
drag: userSelectDriver
});