How to use the @reactivex/rxjs.Observable.fromEvent function in @reactivex/rxjs

To help you get started, we’ve selected a few @reactivex/rxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / javascript-typescript-langserver / src / packages.ts View on Github external
constructor(
		private updater: FileSystemUpdater,
		private inMemoryFileSystem: InMemoryFileSystem,
		private logger: Logger = new NoopLogger()
	) {
		let rootPackageJsonLevel = Infinity;
		// Find locations of package.jsons _not_ inside node_modules
		this.subscriptions.add(
			Observable.fromEvent<[string, string]>(inMemoryFileSystem, 'add', Array.of)
				.subscribe(([uri, content]) => {
					const parts = url.parse(uri);
					if (!parts.pathname	|| !parts.pathname.endsWith('/package.json') || parts.pathname.includes('/node_modules/')) {
						return;
					}
					this.packages.add(uri);
					this.logger.log(`Found package ${uri}`);
					// If the current root package.json is further nested than this one, replace it
					const level = parts.pathname.split('/').length;
					if (level < rootPackageJsonLevel) {
						this.rootPackageJsonUri = uri;
						rootPackageJsonLevel = level;
					}
				})
		);
	}
github machinelabs / machinelabs / server / src / util / process.ts View on Github external
static toObservableProcess(process: ChildProcess) {
    // a simple mapping function to preserve meta info around the data so that we
    // can pump stdout and stderr through one common stream.
    let mapFrom = (origin: string) => (data: Buffer | string) => ({ origin: origin, raw: data, str: data.toString() });

    let stdOutStream = Observable
                        .fromEvent(process.stdout, 'data')
                        .map(mapFrom('stdout'))
                        .share();

    // Since STDERR is a stream just like STDOUT it doesn't
    // really work to propagate that with Observable/error.
    // Instead we combine STDOUT and STDERR to one stream.
    let stdErrStream = Observable
                        .fromEvent(process.stderr, 'data')
                        .map(mapFrom('stderr'))
                        .share();

    let closeStream = Observable.fromEvent(process, 'close').share();

    return Observable.merge(stdOutStream, stdErrStream).takeUntil(closeStream);
  }
github machinelabs / machinelabs / server / src / util / process.ts View on Github external
let mapFrom = (origin: string) => (data: Buffer | string) => ({ origin: origin, raw: data, str: data.toString() });

    let stdOutStream = Observable
                        .fromEvent(process.stdout, 'data')
                        .map(mapFrom('stdout'))
                        .share();

    // Since STDERR is a stream just like STDOUT it doesn't
    // really work to propagate that with Observable/error.
    // Instead we combine STDOUT and STDERR to one stream.
    let stdErrStream = Observable
                        .fromEvent(process.stderr, 'data')
                        .map(mapFrom('stderr'))
                        .share();

    let closeStream = Observable.fromEvent(process, 'close').share();

    return Observable.merge(stdOutStream, stdErrStream).takeUntil(closeStream);
  }
github machinelabs / machinelabs / server / src / util / process.ts View on Github external
static toObservableProcess(process: ChildProcess) {
    // a simple mapping function to preserve meta info around the data so that we
    // can pump stdout and stderr through one common stream.
    let mapFrom = (origin: string) => (data: Buffer | string) => ({ origin: origin, raw: data, str: data.toString() });

    let stdOutStream = Observable
                        .fromEvent(process.stdout, 'data')
                        .map(mapFrom('stdout'))
                        .share();

    // Since STDERR is a stream just like STDOUT it doesn't
    // really work to propagate that with Observable/error.
    // Instead we combine STDOUT and STDERR to one stream.
    let stdErrStream = Observable
                        .fromEvent(process.stderr, 'data')
                        .map(mapFrom('stderr'))
                        .share();

    let closeStream = Observable.fromEvent(process, 'close').share();

    return Observable.merge(stdOutStream, stdErrStream).takeUntil(closeStream);
  }
github microsoft / BotFramework-WebChat / src / ConsoleView.tsx View on Github external
componentDidMount() {
        this.autoscrollSubscription = Observable
            .fromEvent(this.scrollMe, 'scroll')
            .map(e => e.target.scrollTop + e.target.offsetHeight >= e.target.scrollHeight)
            .distinctUntilChanged()
            .subscribe(autoscroll =>
                getStore().dispatch({ type: 'Set_Autoscroll', autoscroll } as ConsoleAction)
            );
        this.consoleSubscription = console$.subscribe(
            entry => {
                let newState: IConsoleViewState = { entries: [...this.state.entries, entry] };
                this.setState(newState);
            }
        )
    }