react-streams
react-streams copied to clipboard
Ideas for Custom Operators
I deprecated switchProps
in favor of coming up with a custom operator approach, but I don't know what it is yet :)
I've also been toying with catchMap
(to render a component when an error is thrown) and other ideas.
Any other ideas?
Looking at the Stream component, it should provide callbacks for both the err
and complete
functions. Usage would be something similar to the following:
handleError = (err) => this.setState((state) => ({ hasError: true, error: err }));
handleComplete = () => this.setState((state) => ({ isComplete: true }));
render = () => (
<React.Fragment>
<Stream source={source$}
error={this.handleError}
complete={this.handleComplete}>
{x => <p>{x.val}</p>}
</Stream>
{this.state.hasError && <p>{this.state.error}</p>}
{this.state.isComplete && <p>Stream Complete!</p>}
</React.Fragment>
)