1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-06-27 15:01:53 +03:00

Add the MatrixClient to the react context

Because that's the reacty way
This commit is contained in:
Richard van der Hoff
2016-11-03 18:54:30 +00:00
parent f85a37c667
commit d3f20e1d9d
2 changed files with 54 additions and 0 deletions

View File

@ -28,6 +28,8 @@ import sdk from '../../index';
*
* Currently it's very tightly coupled with MatrixChat. We should try to do
* something about that.
*
* Components mounted below us can access the matrix client via the react context.
*/
export default React.createClass({
displayName: 'LoggedInView',
@ -42,7 +44,20 @@ export default React.createClass({
// and lots and lots of other stuff.
},
childContextTypes: {
matrixClient: React.PropTypes.instanceOf(Matrix.MatrixClient),
},
getChildContext: function() {
return {
matrixClient: this._matrixClient,
};
},
componentWillMount: function() {
// stash the MatrixClient in case we log out before we are unmounted
this._matrixClient = this.props.matrixClient;
// _scrollStateMap is a map from room id to the scroll state returned by
// RoomView.getScrollState()
this._scrollStateMap = {};