Last active
February 28, 2017 16:13
-
-
Save kamicane/e6a434ff12e623978aba4d0d3d5fab33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { Component } from 'react' | |
import { observe } from '@nx-js/observer-util' | |
export default class ObserverComponent extends Component { | |
componentWillMount () { | |
const render = this.render | |
const initialRender = (...args) => { | |
let result | |
this.signal = observe(() => { | |
if (this.render === initialRender) { | |
result = render.apply(this, args) | |
} else { | |
this.forceUpdate() | |
} | |
}) | |
this.render = render | |
return result | |
} | |
this.render = initialRender | |
} | |
componentWillUnmount () { | |
this.signal.unobserve() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment