bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/modal/service.js

42 lines
921 B
JavaScript
Raw Normal View History

2017-04-19 03:06:51 +08:00
import { Tracker } from 'meteor/tracker';
import React, { Component } from 'react';
2017-06-03 03:25:02 +08:00
const currentModal = {
2017-04-19 03:06:51 +08:00
component: null,
2017-06-03 03:25:02 +08:00
tracker: new Tracker.Dependency(),
2017-04-19 03:06:51 +08:00
};
const showModal = (component) => {
if (currentModal.component !== component) {
currentModal.component = component;
currentModal.tracker.changed();
}
};
export const getModal = () => {
currentModal.tracker.depend();
return currentModal.component;
};
2017-06-03 03:25:02 +08:00
export const withModalMounter = ComponentToWrap =>
2017-04-19 03:06:51 +08:00
class ModalMounterWrapper extends Component {
constructor(props) {
super(props);
this.mount = this.mount.bind(this);
}
mount(modalComponent) {
showModal(null);
// defer the execution to a subsequent event loop
setTimeout(() => showModal(modalComponent), 0);
}
render() {
2017-06-03 03:25:02 +08:00
return (<ComponentToWrap
2017-04-19 03:06:51 +08:00
{...this.props}
mountModal={this.mount}
2017-06-03 03:25:02 +08:00
/>);
2017-04-19 03:06:51 +08:00
}
};