import xs, {Stream, MemoryStream} from 'xstream'; import {adapt} from '@cycle/run/lib/adapt'; import {DevToolEnabledSource} from '@cycle/run'; import {EventsFnOptions, DOMSource} from './DOMSource'; import {fromEvent} from './fromEvent'; export class BodyDOMSource { constructor(private _name: string) {} public select(selector: string): BodyDOMSource { // This functionality is still undefined/undecided. return this; } public elements(): MemoryStream> { const out: DevToolEnabledSource & MemoryStream> = adapt(xs.of([document.body])); out._isCycleSource = this._name; return out; } public element(): MemoryStream { const out: DevToolEnabledSource & MemoryStream = adapt( xs.of(document.body) ); out._isCycleSource = this._name; return out; } public events( eventType: K, options?: EventsFnOptions, bubbles?: boolean ): Stream; public events( eventType: string, options: EventsFnOptions = {}, bubbles?: boolean ): Stream { let stream: Stream; stream = fromEvent( document.body, eventType, options.useCapture, options.preventDefault ); const out: DevToolEnabledSource & Stream = adapt(stream); out._isCycleSource = this._name; return out; } }