How to use @reactivex/rxjs - 10 common examples

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 / typescript-service.ts View on Github external
.filter(uri => uri.startsWith(packageRootUri))
						.mergeMap(uri => this.updater.ensure(uri, span))
						.toArray()
						.mergeMap(() => {
							span.log({ event: 'fetched package files' });
							const config = this.projectManager.getParentConfiguration(packageRootUri, 'ts');
							if (!config) {
								throw new Error(`Could not find tsconfig for ${packageRootUri}`);
							}
							// Don't match PackageDescriptor on symbols
							return this._getSymbolsInConfig(config, params.query || omit(params.symbol!, 'package'), limit, span);
						});
				}
				// Regular workspace symbol search
				// Search all symbols in own code, but not in dependencies
				return Observable.from(this.projectManager.ensureOwnFiles(span))
					.mergeMap(() =>
						params.symbol && params.symbol.package && params.symbol.package.name
							// If SymbolDescriptor query with PackageDescriptor, search for package.jsons with matching package name
							? observableFromIterable(this.packageManager.packageJsonUris())
								.filter(packageJsonUri => (JSON.parse(this.inMemoryFileSystem.getContent(packageJsonUri)) as PackageJson).name === params.symbol!.package!.name)
								// Find their parent and child tsconfigs
								.mergeMap(packageJsonUri => Observable.merge(
									castArray(this.projectManager.getParentConfiguration(packageJsonUri) || []),
									// Search child directories starting at the directory of the package.json
									observableFromIterable(this.projectManager.getChildConfigurations(url.resolve(packageJsonUri, '.')))
								))
							// Else search all tsconfigs in the workspace
							: observableFromIterable(this.projectManager.configurations())
					)
					// If PackageDescriptor is given, only search project with the matching package name
					.mergeMap(config => this._getSymbolsInConfig(config, params.query || params.symbol, limit, span));
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
protected _getPackageDescriptor(uri: string): Observable {
		// Get package name of the dependency in which the symbol is defined in, if any
		const packageName = extractNodeModulesPackageName(uri);
		if (packageName) {
			// The symbol is part of a dependency in node_modules
			// Build URI to package.json of the Dependency
			const encodedPackageName = packageName.split('/').map(encodeURIComponent).join('/');
			const parts = url.parse(uri);
			const packageJsonUri = url.format({ ...parts, pathname: parts.pathname!.slice(0, parts.pathname!.lastIndexOf('/node_modules/' + encodedPackageName)) + `/node_modules/${encodedPackageName}/package.json` });
			// Fetch the package.json of the dependency
			return Observable.from(this.updater.ensure(packageJsonUri))
				.map((): PackageDescriptor | undefined => {
					const packageJson = JSON.parse(this.inMemoryFileSystem.getContent(packageJsonUri));
					const { name, version } = packageJson;
					if (name) {
						// Used by the LSP proxy to shortcut database lookup of repo URL for PackageDescriptor
						let repoURL: string | undefined;
						if (name.startsWith('@types/')) {
							// if the dependency package is an @types/ package, point the repo to DefinitelyTyped
							repoURL = 'https://github.com/DefinitelyTyped/DefinitelyTyped';
						} else {
							// else use repository field from package.json
							repoURL = typeof packageJson.repository === 'object' ? packageJson.repository.url : undefined;
						}
						return { name, version, repoURL };
					}
					return undefined;
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
return (() => {
			try {
				config.ensureAllFiles(span);

				const program = config.getProgram(span);
				if (!program) {
					return Observable.empty();
				}

				if (query) {
					let items: Observable<[number, ts.NavigateToItem]>;
					if (typeof query === 'string') {
						// Query by text query
						items = Observable.from(config.getService().getNavigateToItems(query, limit, undefined, false))
							// Same score for all
							.map(item => [1, item]);
					} else {
						const queryWithoutPackage = omit(query, 'package') as SymbolDescriptor;
						// Query by name
						items = Observable.from(config.getService().getNavigateToItems(query.name || '', limit, undefined, false))
							// Get a score how good the symbol matches the SymbolDescriptor (ignoring PackageDescriptor)
							.map((item): [number, ts.NavigateToItem] => [getMatchScore(queryWithoutPackage, {
								kind: item.kind,
								name: item.name,
								containerKind: item.containerKind,
								containerName: item.containerName
							}), item])
							// If score === 0, no properties matched
							.filter(([score, symbol]) => score > 0)
							// If SymbolDescriptor matched, get package.json and match PackageDescriptor name
github wzr1337 / rsi.server / src / main.ts View on Github external
import { Observable, Subject } from '@reactivex/rxjs';

// set up the server


// register an Object
var mySubject = new Subject();
var subscription = mySubject.subscribe(
  (x:any) => {
    console.log('Next: ' + x);
  },
  (err:any) => {
    console.log('Error: ' + err);
  },
  () => {
    console.log('Completed');
  });


// push info into the Object

mySubject.next('foo');
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 giltig / rxfrf / src / shared / stores / index.js View on Github external
import {Observable} from '@reactivex/rxjs'
import counterStore from './counterStore'
import routerStore from './routerStore'

// You can enter more stores here
export default Observable.combineLatest(counterStore, 
                                        routerStore,
                                        (counterStore, 
                                         routerStore) => {
                                          return Object.assign({}, 
                                                               counterStore,
                                                               routerStore)
                                        })
github OmniSharp / omnisharp-node-client / lib / helpers / pausableBuffered.ts View on Github external
constructor(destination: Subscriber, private _self: Observable, private _pauser: Observable) {
        super(destination);

        let previousShouldFire: boolean;
        destination.add(
            Observable.combineLatest(_self, _pauser)
                .subscribe(([data, shouldFire]) => {
                    if (previousShouldFire !== undefined && shouldFire !== previousShouldFire) {
                        previousShouldFire = shouldFire;
                        // change in shouldFire
                        if (shouldFire) { this._drainQueue(); }
                    } else {
                        previousShouldFire = shouldFire;
                        // new data
                        if (shouldFire) {
                            this._next(data);
                        } else {
                            this._queue.push(data);
                        }
                    }
                }, e => {
                    this._drainQueue();
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
return (() => {
			try {
				config.ensureAllFiles(span);

				const program = config.getProgram(span);
				if (!program) {
					return Observable.empty();
				}

				if (query) {
					let items: Observable<[number, ts.NavigateToItem]>;
					if (typeof query === 'string') {
						// Query by text query
						items = Observable.from(config.getService().getNavigateToItems(query, limit, undefined, false))
							// Same score for all
							.map(item => [1, item]);
					} else {
						const queryWithoutPackage = omit(query, 'package') as SymbolDescriptor;
						// Query by name
						items = Observable.from(config.getService().getNavigateToItems(query.name || '', limit, undefined, false))
							// Get a score how good the symbol matches the SymbolDescriptor (ignoring PackageDescriptor)
							.map((item): [number, ts.NavigateToItem] => [getMatchScore(queryWithoutPackage, {
								kind: item.kind,
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
textDocumentReferences(params: ReferenceParams, span = new Span()): Observable {
		const uri = normalizeUri(params.textDocument.uri);

		// Ensure all files were fetched to collect all references
		return Observable.from(this.projectManager.ensureOwnFiles(span))
			.mergeMap(() => {
				// Convert URI to file path because TypeScript doesn't work with URIs
				const fileName = uri2path(uri);
				// Get tsconfig configuration for requested file
				const configuration = this.projectManager.getConfiguration(fileName);
				// Ensure all files have been added
				configuration.ensureAllFiles(span);
				const program = configuration.getProgram(span);
				if (!program) {
					return [];
				}
				// Get SourceFile object for requested file
				const sourceFile = this._getSourceFile(configuration, fileName, span);
				if (!sourceFile) {
					throw new Error(`Source file ${fileName} does not exist`);
				}
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
}), item])
							// If score === 0, no properties matched
							.filter(([score, symbol]) => score > 0)
							// If SymbolDescriptor matched, get package.json and match PackageDescriptor name
							// TODO get and match full PackageDescriptor (version)
							.mergeMap(([score, item]) => {
								if (!query.package || !query.package.name) {
									return [[score, item]];
								}
								const uri = path2uri('', item.fileName);
								return Observable.from(this.packageManager.getClosestPackageJson(uri, span))
									// If PackageDescriptor matches, increase score
									.map((packageJson): [number, ts.NavigateToItem] => packageJson && packageJson.name === query.package!.name! ? [score + 1, item] : [score, item]);
							});
					}
					return Observable.from(items)
						// Map NavigateToItems to SymbolInformations
						.map(([score, item]) => {
							const sourceFile = program.getSourceFile(item.fileName);
							if (!sourceFile) {
								throw new Error(`Source file ${item.fileName} does not exist`);
							}
							const symbolInformation: SymbolInformation = {
								name: item.name,
								kind: convertStringtoSymbolKind(item.kind),
								location: {
									uri: this._defUri(item.fileName),
									range: {
										start: ts.getLineAndCharacterOfPosition(sourceFile, item.textSpan.start),
										end: ts.getLineAndCharacterOfPosition(sourceFile, item.textSpan.start + item.textSpan.length)
									}
								}