2018-04-03 22:56:12 +00:00
|
|
|
/* global Backbone: false */
|
|
|
|
|
|
|
|
// Additional globals used:
|
|
|
|
// window.React
|
|
|
|
// window.ReactDOM
|
|
|
|
// window.i18n
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2018-04-11 16:30:28 +00:00
|
|
|
window.Whisper.ReactWrapperView = Backbone.View.extend({
|
2018-04-03 22:56:12 +00:00
|
|
|
className: 'react-wrapper',
|
|
|
|
initialize(options) {
|
|
|
|
const { Component, props, onClose } = options;
|
|
|
|
this.render();
|
|
|
|
|
2018-04-17 16:39:41 +00:00
|
|
|
this.tagName = options.tagName;
|
|
|
|
this.className = options.className;
|
2018-04-03 22:56:12 +00:00
|
|
|
this.Component = Component;
|
|
|
|
this.onClose = onClose;
|
|
|
|
|
|
|
|
this.update(props);
|
|
|
|
},
|
|
|
|
update(props) {
|
|
|
|
const updatedProps = this.augmentProps(props);
|
|
|
|
const element = window.React.createElement(this.Component, updatedProps);
|
|
|
|
window.ReactDOM.render(element, this.el);
|
|
|
|
},
|
|
|
|
augmentProps(props) {
|
|
|
|
return Object.assign({}, props, {
|
|
|
|
close: () => {
|
|
|
|
if (this.onClose) {
|
|
|
|
this.onClose();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.remove();
|
|
|
|
},
|
|
|
|
i18n: window.i18n,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
remove() {
|
|
|
|
window.ReactDOM.unmountComponentAtNode(this.el);
|
|
|
|
Backbone.View.prototype.remove.call(this);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}());
|