react-streams icon indicating copy to clipboard operation
react-streams copied to clipboard

Ideas for Custom Operators

Open johnlindquist opened this issue 6 years ago • 1 comments

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?

johnlindquist avatar Apr 09 '18 14:04 johnlindquist

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>
)

JaimeStill avatar Oct 29 '18 14:10 JaimeStill