Last active
April 6, 2019 22:01
-
-
Save dezfowler/0367ac91901a0026fdddab397d87c634 to your computer and use it in GitHub Desktop.
Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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