question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[discussion] clean imports to replace `rxjs/add/observable/xyz`

See original GitHub issue

Now that lettable operators are coming (#2667) to get rid of the import 'rxjs/add/operator/xyz' mess, the static Observable methods for creation (of, timer, …) and composition (merge, zip, …) will probably need the same treatment to get rid of import 'rxjs/add/observable/xyz'.

I didn’t find any issue or PR for this (probably not in scope of #2667, judging by the title and current commits), but I’m sure @benlesh has some ideas already?

It already seems to be possible to import these static methods properly using import { merge } from 'rxjs/observable/merge' etc, although this is not documented in the installation section of the docs. However, if I didn’t miss anything this approach seems quite clunky because

  1. each method requires a separate import statement
  2. the imports are not available on one central object like they are on Observable when using the add/observable imports
  3. resulting from 2, they may need to be aliased because e.g. merge is a very generic name that does not convey correlation with RxJS

My personal comments on this: 1 could be resolved by centralizing the exports of the static methods similar to the rxjs/operators from #2667 2 does not appear to have an obvious solution, unfortunately there is no import { merge, zip } as ObservableFactoryThingy unless you’re importing everything (*) 3 is probably not a large problem, especially since the same thing will apply for lettable operators (map, min etc). I certainly don’t think it justifies exporting them as observableOf, mergeObservables etc instead. Either way, a possible solution to 2 might resolve 3 as well.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
benleshcommented, Dec 1, 2017

FWIW: There has always been the ability to import these directly via:

import { of } from 'rxjs/observable/of';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { timer } from 'rxjs/observable/timer';

The only noteworthy exceptions are throw and if, which are exported with underscores because of keyword collisions:

import { _if } from 'rxjs/observable/if';
import [ _throw } from 'rxjs/observable/throw';
0reactions
lock[bot]commented, Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RxJS Tip: Understand the Terminology: Observable
An Observable is a collection of items over time. It is one of the key building blocks of RxJS. A normal collection, such...
Read more >
Angular Tips: Avoiding duplication of RxJS operator imports
Some people like to import RxJS as import {Observable} from 'rxjs';. With this code, you do not need to import each operator manually....
Read more >
RxJS Operators
RxJS is mostly useful for its operators, even though the Observable is the foundation. Operators are the essential pieces that allow complex asynchronous ......
Read more >
Unlocking reactivity with Svelte and RxJS - Tim Deschryver
This is important if we want to use RxJS in Svelte. ... import { ... we can replace the store implementation with any...
Read more >
angular/angular - Gitter
import { timer, Observable } from 'rxjs'; ... I agree, but then I have to add all those headers to each and evey...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found