You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Migrate away from Legacy React Contexts
This commit is contained in:
@ -36,27 +36,14 @@ const test_utils = require('test-utils');
|
||||
const mockclock = require('mock-clock');
|
||||
|
||||
import Velocity from 'velocity-animate';
|
||||
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
||||
import RoomContext from "../../../src/contexts/RoomContext";
|
||||
|
||||
let client;
|
||||
const room = new Matrix.Room();
|
||||
|
||||
// wrap MessagePanel with a component which provides the MatrixClient in the context.
|
||||
const WrappedMessagePanel = createReactClass({
|
||||
childContextTypes: {
|
||||
matrixClient: PropTypes.object,
|
||||
room: PropTypes.object,
|
||||
},
|
||||
|
||||
getChildContext: function() {
|
||||
return {
|
||||
matrixClient: client,
|
||||
room: {
|
||||
canReact: true,
|
||||
canReply: true,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
resizeNotifier: new EventEmitter(),
|
||||
@ -64,7 +51,11 @@ const WrappedMessagePanel = createReactClass({
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return <MessagePanel room={room} {...this.props} resizeNotifier={this.state.resizeNotifier} />;
|
||||
return <MatrixClientContext.Provider value={client}>
|
||||
<RoomContext.Provider value={{ canReact: true, canReply: true }}>
|
||||
<MessagePanel room={room} {...this.props} resizeNotifier={this.state.resizeNotifier} />
|
||||
</RoomContext.Provider>
|
||||
</MatrixClientContext.Provider>;
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -9,6 +9,7 @@ import jssdk from 'matrix-js-sdk';
|
||||
import {makeType} from "../src/utils/TypeUtils";
|
||||
import {ValidatedServerConfig} from "../src/utils/AutoDiscoveryUtils";
|
||||
import ShallowRenderer from 'react-test-renderer/shallow';
|
||||
import MatrixClientContext from "../src/contexts/MatrixClientContext";
|
||||
const MatrixEvent = jssdk.MatrixEvent;
|
||||
|
||||
/**
|
||||
@ -291,22 +292,16 @@ export function getDispatchForStore(store) {
|
||||
|
||||
export function wrapInMatrixClientContext(WrappedComponent) {
|
||||
class Wrapper extends React.Component {
|
||||
static childContextTypes = {
|
||||
matrixClient: PropTypes.object,
|
||||
}
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
getChildContext() {
|
||||
return {
|
||||
matrixClient: this._matrixClient,
|
||||
};
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this._matrixClient = peg.get();
|
||||
}
|
||||
|
||||
render() {
|
||||
return <WrappedComponent ref={this.props.wrappedRef} {...this.props} />;
|
||||
return <MatrixClientContext.Provider value={this._matrixClient}>
|
||||
<WrappedComponent ref={this.props.wrappedRef} {...this.props} />
|
||||
</MatrixClientContext.Provider>;
|
||||
}
|
||||
}
|
||||
return Wrapper;
|
||||
|
Reference in New Issue
Block a user