-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
addListener() to not require all three next, error, and complete functions #67
Comments
I know it's cumbersome, and it's primarily an experiment in API design, I wanted to make it cumbersome to do things that are not supposed to be done often. Like it's cumbersome to write That said, you use it often in unit tests. So what I'm interested in is to see how your unit tests look like. Can you show a small example? We could end up creating a new API just for tests, like e.g. |
I understand the reasons, but having an inflexible API has downsides as well. Problem is also with e.g. webpackbins (and they help us learn a lot). We could add an undocumented wrapper function like stream.subscribe(fnNext) but that probably just adds to the confusion. I would prefer overload on addListener. Anyway, here is a unit test sample: t('Controls action$', (t) => {
const config = {
'.btn-backward' : { 'click': xs.of(1) },
'.btn-forward' : { 'click': xs.of(1) },
'.btn-play' : { 'click': xs.of(1) }
};
const expected = [ {type: "BACKWARD"}, {type: "FORWARD"}, {type: "PLAY"} ];
const action$ = Controls({ DOM : utils.mockDOM(config) }).action$;
const actual$ = utils.toArray(action$);
actual$
.addListener(utils.listen(actual => {
t.deepEqual(actual, expected);
t.end();
}));
}); Here I wrap the listener in utils.listen and that works fine, but we still have the issue when spinning something up in webpackbin. I actually copy/paste from Webstorm(!). PS: I you want to keep it the way it is, that is fine and I understand, just providing feedback 😄 |
I also find XStream learning process encomplicated by annoying It was said you don't need them often in production. I was surprised to get much more boilerplate with XStream than with Rx. Just one example: sometimes it's not immediately obvious which In RxJS: change suffixes. You guys really need to consider functional API where all this expression problem stuff no longer exists and |
If you're writing shamefullySendNext or addListener too often, you're using xstream for something it's not meant for.
If you need any other strategy than
What's in
|
I said my usecases. 10 examples to demonstrate how
It is a hack around expression problem. It was a hack in all other implementations as well.
Aren't my usecases also a statistics? |
No these are not xstream use cases. xstream is for Cycle.js or similar use case.
This is potentially true, and we could eventually move concat and flattenSequentially into core, but we'd do that conservatively, waiting first for the community to express how often they use it.
I don't know what is your definition of hack, but IMO it's not a hack. |
So people are expected to
How do you propose to use it without learning it. And if learning is encomplicated it's not good.
Well, I've just expressed my opinion. One vote for particular things – not pretending for more. |
We don't need to use |
Ok, I will consider this. |
I would make stream$.addListener((msg: string) => console.log(msg)) That would remove user annoyance when have to use |
It's easy to create a small function to work in whatever way you prefer. function listen (next, stream) {
const listener = {
next,
error: Function.prototype,
complete: Function.prototype
}
stream.addListener(listener)
return () => stream.removeListener(listener)
}
const unsubscribe = listen(x => console.log(x), stream)
// later
unsubscribe() |
Yes it is easy, but not every time you need this, it just creates unnecessary annoyance. Yes and it could also return "unlisten". |
Stream.addListener can now accept a listener that is partially defined. This means that it does not require all three callbacks. One or two or all of the callbacks can be given, and it will still work as expected. #67
@mspoulsen this is now available in v6.6.0 :) |
Excellent! Thank you very much 👍 |
How do you guys feel about removing this requirement?
I personally think it makes code (especially unit tests) clunky. I like the way Rx allow you to pass in 1-3 functions instead of the complete listener object. I understand the reasons you designed it this way but in unit tests we use addListener all the time.
stream.addListener(fnNext, fnError?, fnCompleted?) would be really nice :)
I can of course make a wrapper for my unit tests and I have already but same argument applies when we create small sample code in webpackbin etc. Adding the listener is pretty cumbersome, so would be nice to be able to add just the next function.
The text was updated successfully, but these errors were encountered: