Last active
August 29, 2015 14:24
-
-
Save Jyrno42/4b376968bd15a6b4809a to your computer and use it in GitHub Desktop.
How i sneak past the issue with Alt Render.toDOM and conflicting react router handler. see https://github.com/goatslacker/alt/issues/334
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
// Just add export for dispatchbuffer in src/utils/Render.js | |
- class DispatchBuffer { | |
+ export class DispatchBuffer { |
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 React from 'react'; | |
import Iso from 'iso'; | |
import {DispatchBuffer} from "alt/utils/Render"; | |
import Router from 'react-router'; | |
import routes from './routes'; | |
import alt from './alt'; | |
// Run AltIso | |
Iso.on('iso', 1, function (state, meta, container) { | |
alt.bootstrap(state); | |
Router.run(routes, Router.HistoryLocation, (Handler, props) => { | |
props.buffer = new DispatchBuffer(); | |
React.render(<Handler {...props} />, container) | |
}); | |
}); |
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 React from 'react'; | |
/** | |
* Helper Component which lets us sneak past this issue: | |
* | |
* - https://github.com/goatslacker/alt/issues/334 | |
* | |
* Note: Just a passthrough server-side | |
* | |
* @param Component | |
* @return {*} | |
*/ | |
function withBuffer(Component) { | |
let classObj = { | |
render() { | |
return (<Component {...this.props} />); | |
} | |
}; | |
if (typeof window !== 'undefined') { | |
classObj.getChildContext = function () { | |
return { buffer: this.props.buffer }; | |
}; | |
classObj.childContextTypes = { | |
buffer: React.PropTypes.object.isRequired | |
}; | |
} | |
return React.createClass(classObj); | |
} | |
export default withBuffer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment