Skip to content

Instantly share code, notes, and snippets.

@dezfowler
Last active April 6, 2019 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dezfowler/0367ac91901a0026fdddab397d87c634 to your computer and use it in GitHub Desktop.
Save dezfowler/0367ac91901a0026fdddab397d87c634 to your computer and use it in GitHub Desktop.
Testing
import { Subject } from 'rxjs';
import { tap } from 'rxjs/operators';
export const rxify = renderStreamFactory =>
class Rxified extends React.Component {
constructor(props) {
super(props);
this.state = null;
}
componentDidMount() {
this.propsChangeSubject = new Subject();
this.subscription = renderStreamFactory(this.props, this.propsChangeSubject)
.pipe(
tap(node => this.setState(node))
)
.subscribe();
this.propsChangeSubject.next(this.props);
}
componentWillUnmount() {
if (this.subscription) {
this.subscription.dispose();
}
}
componentDidUpdate(prevProps) {
if (this.props != prevProps) {
this.propsChangeSubject.next(this.props);
}
}
render() {
return this.state;
}
};
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('rxjs/operators')) :
typeof define === 'function' && define.amd ? define('rxact', ['exports', 'rxjs', 'rxjs/operators'], factory) :
(global = global || self, factory(global.rxact = {}, global.rxjs, global.rxjs.operators));
}(this, function (exports, rxjs, operators) { 'use strict';
const rxify = renderStreamFactory =>
class Rxified extends React.Component {
constructor(props) {
super(props);
this.state = null;
}
componentDidMount() {
this.propsChangeSubject = new rxjs.Subject();
this.subscription = renderStreamFactory(this.props, this.propsChangeSubject)
.pipe(
operators.tap(node => this.setState(node))
)
.subscribe();
this.propsChangeSubject.next(this.props);
}
componentWillUnmount() {
if (this.subscription) {
this.subscription.dispose();
}
}
componentDidUpdate(prevProps) {
if (this.props != prevProps) {
this.propsChangeSubject.next(this.props);
}
}
render() {
return this.state;
}
};
exports.rxify = rxify;
Object.defineProperty(exports, '__esModule', { value: true });
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment