jsketcher/modules/ui/connect.js
2018-06-22 00:31:33 -07:00

29 lines
660 B
JavaScript

import React from 'react';
import context from 'context';
export default function connect(streamProvider) {
return function (Component) {
return class Connected extends React.Component {
streamProps = {};
componentWillMount() {
let stream = streamProvider(context.streams, this.props);
this.detacher = stream.attach(data => {
this.streamProps = data;
this.forceUpdate();
});
}
componentWillUnmount() {
this.detacher();
}
render() {
return <Component {...this.streamProps}
{...this.props} />;
}
};
}
}