Preserve scroll position when adding/removing staged quote

This commit is contained in:
Scott Nonnenberg 2019-01-14 19:20:45 -08:00
parent cba47668cd
commit 7db7a3ad44
4 changed files with 59 additions and 24 deletions

View file

@ -12,20 +12,43 @@
window.Whisper.ReactWrapperView = Backbone.View.extend({
className: 'react-wrapper',
initialize(options) {
const { Component, props, onClose } = options;
const {
Component,
props,
onClose,
tagName,
className,
onInitialRender,
elCallback,
} = options;
this.render();
if (elCallback) {
elCallback(this.el);
}
this.tagName = options.tagName;
this.className = options.className;
this.tagName = tagName;
this.className = className;
this.Component = Component;
this.onClose = onClose;
this.onInitialRender = onInitialRender;
this.update(props);
this.hasRendered = false;
},
update(props) {
const updatedProps = this.augmentProps(props);
const reactElement = React.createElement(this.Component, updatedProps);
ReactDOM.render(reactElement, this.el);
ReactDOM.render(reactElement, this.el, () => {
if (this.hasRendered) {
return;
}
this.hasRendered = true;
if (this.onInitialRender) {
this.onInitialRender();
}
});
},
augmentProps(props) {
return Object.assign({}, props, {