Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pipeable operators #11

Open
Airblader opened this issue Jan 28, 2018 · 8 comments
Open

Support pipeable operators #11

Airblader opened this issue Jan 28, 2018 · 8 comments

Comments

@Airblader
Copy link
Contributor

Closing #4 was a little premature. We can write our own pipeable operators and use them now, but due to the way rxjs is imported in the sandbox we cannot use all the built-ins as pipeable operators. For example, ideally this would work:

const source$ = of(42);
source$.pipe(
  map(value => 2 * value)
)

This would be really useful to quickly copy-paste samples from code you're writing to debug them as well as allow using rxviz as a reference for answers on platforms such as StackOverflow.

@Airblader
Copy link
Contributor Author

I'm happy to implement this, but I'm not sure what a good way to achieve this would be. Manually import all known operators in the sandbox? AFAIK there's no good way to automatically import all operators without listing them explicitly.

@moroshko
Copy link
Owner

I'm not it's a good idea to pollute the global scope with all the available operators.

You can just do:

const { of } = Rx.Observable;
const { map } = Rx.operators;
const source$ = of(42);

source$.pipe(
  map(value => 2 * value)
)

@Airblader Airblader reopened this Jan 29, 2018
@Airblader
Copy link
Contributor Author

In general I agree, especially considering that functionally there's nothing we can't do already. However, to provide some perspective, I've been using rxviz every day for a while now. I use I for my work, I use it for private work and I use it when answering questions on StackOverflow. The two issues I run into almost every time are:

  1. Having to use the Rx name space rather than writing Observable etc directly
  2. No option to directly write pipeable operators.

Both can be worked around the way you describe, but it's just not as convenient as it could be for copy-pasting snippets in either direction.

I guess one thing I could do is prepare a snippet which does all the global scope aliasing, save its URL and bookmark it to use it as my starter template. That might be good enough.

@MattiJarvinen
Copy link

@moroshko you should upgrade couple of examples to use lettable operators just to show this functionality. Prehaps add those already into comment block of the custom code page.

This tool is awesome, thanks for this.

@Liero
Copy link

Liero commented Jun 8, 2019

@Airblader: rather that polluting global scope, I would expect something like quickfix command in editor that adds the imports.

Maybe some visual toolbox, with all operators, creators etc. and their description would also help.

@Akxe
Copy link

Akxe commented Aug 29, 2019

@Liero That could be theoretically done using with keyword, but it is not recommended. And there is a problem that, there are non-ambiguous creators/operators. combineLatest is one example.

I would vote for import syntax. Imports are used in every app that uses RXJS, it solves ambiguities problem and is easily copy/paste able.

@rraziel
Copy link
Collaborator

rraziel commented Aug 7, 2020

Hello @Airblader ,

It's been a while but, as mentioned before, having them available in the global scope can be an issue, most notably with name clashes for things like combineLatest that exist in 2 forms.

However I can see how in its current state this is not very user-friendly. What do you think about:

Short-term

Automatically turn import statements into their rxviz equivalent, e.g when pasting:

import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';

It becomes:

const { combineLatest } = Rx
const { map } = Rx.operators

Long-term

That would require far more work, but having something that provides auto-completion and adds imports should make the application far easier to use as an editor

@Akxe
Copy link

Akxe commented Aug 13, 2020

@rraziel For the long term, this should work https://github.com/cdr/code-server.

Stripped down VSCode would work wonders...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants