import * as React from "react" import * as effects from "./effect" let __stream export default class Stream extends React.Component<{ onAction: (action: any) => void, url: string }> { public listener: any constructor(props) { super(props) this.listener = { next: props.onAction } } public componentDidMount() { if (!__stream) { const urls = (this.props.url || "").split(",") const url = urls[Math.floor(Math.random() * urls.length)] __stream = effects.controlStream(XMLHttpRequest, url) } __stream.addListener(this.listener) } public componentWillUnmount() { __stream.removeListener(this.listener) } public render() { return null } }