-
-
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
exhaustMap equivalent #157
Comments
@MidnightWonderer Hi. In that case you would need to implement it yourself (following the example of flattenConcurrently in extras), publish it as a separate library, and use it with compose. |
Do you want to do something like The following should be an acceptable operator implementing only exhaust. import xs, { Stream } from 'xstream';
import flattenSequentially from 'xstream/extra/flattenSequentially';
function exhaust<T>( source ): Stream<T> {
/* Initialize listening status to false. */
let listening: boolean = false;
/**
* Project the source into a stream of streams.
* Each will have a value or be empty.
*/
const projected = source.map( element => xs.of( element ) ).map( project );
function project( inner ) {
/* We're not listening, project the element. */
if ( !listening ) {
/* Toggle listening status. */
listening = true;
/* When that stream ends, set listening status to false. */
inner.addListener({
complete: () => {
listening = false;
},
});
/* Return the inner stream. */
return inner;
}
/* We're already listening, emit nothing. */
return xs.empty();
}
/* Flatten the result streams into a single stream. */
return projected.compose( flattenSequentially );
} You would use this operator as @staltz says, using /* Create a source. */
const source = xs.periodic( 100 );
/* Use the operator. */
source.compose( exhaust ); If you also wanted the projection capabilities in function exhaustMap( selector ) {
return function exhaust<T>( source ): Stream<T> {
// ...
/**
* Project the source into a stream of streams.
* Each will have a value or be empty.
*/
const projected = source.map( selector ).map( project );
function project( element ) {
// ...
}
// ...
}
} And you can use this operator by providing a selector. Here is a bin. import delay from 'xstream/extra/delay';
const source = xs.periodic( 1000 );
const selector = () => xs.from( [ 1, 2, 3] ).compose( delay( 1000 ) );
source.compose( exhaustMap( selector ) ); Does this help you implement your feature? |
Hi I think it would be nice if xstream also support operator monkey patching like in rxjs 5. |
Ahh sorry I reread the docs. So do you actually accept pull request for more operator into |
A better place for exhaust would be as a separate library. One of the goals of xstream is to not have many operators, even if they are |
@staltz thank you for the reply. Then I curious how do you justify which functionality should be in core and which one should be in extra? |
It only answers part of your question, @MidnightWonderer, but there is a conversation in #128 about an installation helper to "monkey patch" extra operators. Ideally that helper would be able to "install" operators that are bundled as part of xstream's extras, or your own. I'm hoping to take a stab at that (#128) soon, but the holidays are getting busier. |
Operators in core were the most commonly used RxJS operators in Cycle.js apps. We measured this statistically. We want to keep core around 4kB gzipped/minified. Basically core operators are common for idiomatic Cycle.js and usually you can easily build other operators through some combination of core operators. It's very important that xstream has few operators. It's a feature. Extra are operators equivalent to RxJS operators commonly used in Cycle.js apps, but not as common as core. I've never seen a use case for exhaust in Cycle.js. But as I said, this is the type of thing that can perfectly exist in its own package, then you import
Ideally we would have |
Thank you both for the clarification. |
Hi there
I am new to xstream and I want to use something like
exhaustMap
operation.I can not figure out what to do given the available operators (anything like
flattenFirst
maybe).What do I do?
The text was updated successfully, but these errors were encountered: