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

How to convert an event emitter to a Stream #242

Closed
mspoulsen opened this issue Jun 26, 2018 · 5 comments
Closed

How to convert an event emitter to a Stream #242

mspoulsen opened this issue Jun 26, 2018 · 5 comments

Comments

@mspoulsen
Copy link

Yesterday I posted an issue regarding @most/create: #241

It was closed because we all thought we had a solution. But I don't think we do. So I have taken the liberty to create similar but slightly different issue. My question is:

How do I turn event emitters into a Stream? 😮

Event emitters come in many flavors. It could be a socket.io connection or like the example below, an animation library (this example is from popmotion):

tween().start(n => console.log(n))

Promises will not work, since a Promise only returns one value and I need to be able to push values to the Stream as they arrive.

most/create

create from the @most/create package would work. This function makes it nice and simple to push values to a stream, making it easy to write adapters for almost anything:

const stream$ = create(
    add => {
      tween(tweenProps).start((n: number) => add(n))
    })

However, @most/create does not seem to be compatible with @most/core? The type Stream have changed in @most/core.

Are there any plans to update the @most/create package?
Or can this be done using operators (that I am missing) in @most/core ?

Thanks in advance!

@mspoulsen mspoulsen changed the title How to convert event emitter to a Stream How to convert an event emitter to a Stream Jun 26, 2018
@davidchase
Copy link
Member

@mspoulsen welcome back😛I don’t know if this https://github.com/mostjs-community/from-event/blob/master/README.md supports the new mostjs core but there you have it support event emitters.

Again I think it’s pretty simple to extract the source/sink pattern and create your own operators that you can submit to the community etc

@mspoulsen
Copy link
Author

I have created my own adapters using the pattern from most from-event and it works like a charm. Thanks for your help! 👍 🙂

@davidchase
Copy link
Member

Sweet glad to help

@davidchase
Copy link
Member

looks like this is also good to close 👍

@gblok
Copy link

gblok commented May 19, 2019

how emit/receive multiple arguments?
mostjs-community/from-event#10

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

3 participants