2018-04-03 22:56:12 +00:00
|
|
|
/* global Backbone: false */
|
2018-04-15 03:27:38 +00:00
|
|
|
/* global i18n: false */
|
|
|
|
/* global React: false */
|
|
|
|
/* global ReactDOM: false */
|
2018-04-03 22:56:12 +00:00
|
|
|
|
|
|
|
// 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);
|
2018-04-15 03:27:38 +00:00
|
|
|
const reactElement = React.createElement(this.Component, updatedProps);
|
|
|
|
ReactDOM.render(reactElement, this.el);
|
2018-04-03 22:56:12 +00:00
|
|
|
},
|
|
|
|
augmentProps(props) {
|
|
|
|
return Object.assign({}, props, {
|
|
|
|
close: () => {
|
|
|
|
if (this.onClose) {
|
|
|
|
this.onClose();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.remove();
|
|
|
|
},
|
2018-04-15 03:27:38 +00:00
|
|
|
i18n,
|
2018-04-03 22:56:12 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
remove() {
|
2018-04-15 03:27:38 +00:00
|
|
|
ReactDOM.unmountComponentAtNode(this.el);
|
2018-04-03 22:56:12 +00:00
|
|
|
Backbone.View.prototype.remove.call(this);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}());
|