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

Make Kefir.combine() also accept sources as objects #143

Closed
rpominov opened this issue Sep 5, 2015 · 10 comments
Closed

Make Kefir.combine() also accept sources as objects #143

rpominov opened this issue Sep 5, 2015 · 10 comments

Comments

@rpominov
Copy link
Member

rpominov commented Sep 5, 2015

Currently combine accepts source observables in arrays, but nothing stops us from also supporting objects as containers for sources.

For instance:

const sumStream = Kefir.combine({a: aStream, b: bStream}, ({a, b}) => a + b)

This basically will make combine support named parameters, which is better than parameters as a list.

Also this will work:

Kefir.combine({a: aStream, b: bStream}).log()
// <value> {a: 1, b: 2}

Note: not proposing supporting nested objects, or simple values beside observables, as Bacon. combineTemplate() does. Only shallow "maps" of {[string]: Observable}.

If someone wants to do this, PR is very welcomed!

@niahoo
Copy link

niahoo commented Feb 10, 2016

Hi !

I'm interested into this. What do you think about passive sources ?

@rpominov
Copy link
Member Author

Hey, @niahoo! I think passive sources should work as well e.g., we should be able to do Kefir.combine({a: aStream}, {b: bStream}, ({a, b}) => a + b)

@mAAdhaTTah
Copy link
Collaborator

I'm looking at implementing this, as this would be really useful for something I'm working on. This one is easy enough:

Kefir.combine({a: aStream, b: bStream}).log()
// <value> {a: 1, b: 2}

How do we output the instance method?

aStream.combine({b: bStream}).log()
// <value> {[key?]: 1, b: 2}

@rpominov
Copy link
Member Author

I think we should add support only to the static method.

@rpominov
Copy link
Member Author

Thanks that you're looking into it, btw!

@iofjuupasli
Copy link

iofjuupasli commented Aug 15, 2016

https://github.com/iofjuupasli/kefir-combine-object

It's far from perfect (Ramda dependency), but if you need object combine right now, this can be helpful

mAAdhaTTah referenced this issue in mAAdhaTTah/brookjs Aug 28, 2016
When we get https://github.com/rpominov/kefir/issues/143 in, we
can kill the function that combines them into an object, and either
wrap or pass combinator in directly without all of this ceremony
inline.
32bitkid pushed a commit to 32bitkid/kefir that referenced this issue Oct 19, 2016
A small wrapper on top of combine() to support handling objects instead of arrays.

A potential resolution to kefirjs#143
@32bitkid
Copy link
Contributor

32bitkid commented Oct 19, 2016

I've pulled out a wrapper that I often use; does it need to alter the existing combine() or should it be its own method? I took the safer road with ce68e16; combineProps() (name influenced by .props() in bluebird which does something similar) is just syntatic sugar on top of combine().

Was thinking about rolling the implemenation together, but then was kind of weirded out about mixed signatures:

Kefir.combine({a: aStream, b: bStream}, [cStream, dStream], (???) => {})

@rpominov
Copy link
Member Author

rpominov commented Oct 20, 2016

I'm on the fence. We certainly should not support combining objects with arrays, so if we overload combine and someone calls it with an object and array it should just throw. But maybe having separate method is also a good idea.

Really not sure what is the best call here, if you're about to make a PR just do what feels right for you 😄

One more thing: I think this method should not wrap existing combine, should be implemented similarly to combine itself, either as part of combine implementation or as a separate method with similar code.

@32bitkid
Copy link
Contributor

Sounds good. I'll marinate on it a bit and then make a proper pr

On Oct 20, 2016, at 4:03 AM, Roman Pominov notifications@github.com wrote:

I'm on the fence. We certainly should not support combining objects with arrays, so if we overload combine and someone calls it with an object and array it should just throw. But maybe having separate method is also a good idea.

Really not sure what is the best call here, if you're about to make a PR just do what feels right for you 😄

One more thing: I think this method should not wrap existing combine, should be implemented similarly to combine itself, either as part of combine implementation or as separate method with similar code.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

32bitkid pushed a commit to 32bitkid/kefir that referenced this issue Oct 20, 2016
32bitkid pushed a commit to 32bitkid/kefir that referenced this issue Dec 28, 2016
rpominov added a commit that referenced this issue Dec 31, 2016
* master:
  cleanup repository after release
  3.7.0
  update changelog
  #143 Make Kefir.combine() also accept sources as objects (#225)
  fix RxJS url (#231)
@mAAdhaTTah
Copy link
Collaborator

This landed already so we can close this one.

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

No branches or pull requests

5 participants