1
0
mirror of https://github.com/flarum/core.git synced 2025-10-21 19:56:29 +02:00

Use all Mithril lifecycle stubs (#2847)

This commit is contained in:
Alexander Skvortsov
2021-05-09 18:09:45 -04:00
committed by GitHub
parent ceb567779e
commit d4e3254395
17 changed files with 77 additions and 23 deletions

View File

@@ -24,7 +24,9 @@ export default class AffixedSidebar extends Component {
$(window).on('resize', this.boundOnresize).resize();
}
onremove() {
onremove(vnode) {
super.onremove(vnode);
$(window).off('resize', this.boundOnresize);
}

View File

@@ -56,7 +56,9 @@ export default class Composer extends Component {
);
}
onupdate() {
onupdate(vnode) {
super.onupdate(vnode);
if (this.state.position === this.prevPosition) {
// Set the height of the Composer element and its contents on each redraw,
// so that they do not lose it if their DOM elements are recreated.
@@ -95,7 +97,9 @@ export default class Composer extends Component {
.on('mouseup', (this.handlers.onmouseup = this.onmouseup.bind(this)));
}
onremove() {
onremove(vnode) {
super.onremove(vnode);
$(window).off('resize', this.handlers.onresize);
$(document).off('mousemove', this.handlers.onmousemove).off('mouseup', this.handlers.onmouseup);

View File

@@ -48,7 +48,9 @@ export default class ComposerPostPreview extends Component {
this.updateInterval = setInterval(updatePreview, 50);
}
onremove() {
onremove(vnode) {
super.onremove(vnode);
clearInterval(this.updateInterval);
}
}

View File

@@ -51,8 +51,9 @@ export default class DiscussionPage extends Page {
this.bodyClass = 'App--discussion';
}
onremove() {
super.onremove();
onremove(vnode) {
super.onremove(vnode);
// If we are indeed navigating away from this discussion, then disable the
// discussion list pane. Also, if we're composing a reply to this
// discussion, minimize the composer unless it's empty, in which case

View File

@@ -116,14 +116,16 @@ export default class IndexPage extends Page {
}
}
onbeforeremove() {
onbeforeremove(vnode) {
super.onbeforeremove(vnode);
// Save the scroll position so we can restore it when we return to the
// discussion list.
app.cache.scrollTop = $(window).scrollTop();
}
onremove() {
super.onremove();
onremove(vnode) {
super.onremove(vnode);
$('#app').css('min-height', '');
}

View File

@@ -107,7 +107,9 @@ export default class NotificationList extends Component {
this.$scrollParent.on('scroll', this.boundScrollHandler);
}
onremove() {
onremove(vnode) {
super.onremove(vnode);
this.$scrollParent.off('scroll', this.boundScrollHandler);
}

View File

@@ -85,7 +85,9 @@ export default class Post extends Component {
return this.subtree.needsRebuild();
}
onupdate() {
onupdate(vnode) {
super.onupdate(vnode);
const $actions = this.$('.Post-actions');
const $controls = this.$('.Post-controls');

View File

@@ -40,7 +40,9 @@ export default class PostEdited extends Component {
this.rebuildTooltip();
}
onupdate() {
onupdate(vnode) {
super.onupdate(vnode);
this.rebuildTooltip();
}

View File

@@ -106,7 +106,9 @@ export default class PostStream extends Component {
return <div className="PostStream">{items}</div>;
}
onupdate() {
onupdate(vnode) {
super.onupdate(vnode);
this.triggerScroll();
}
@@ -120,7 +122,9 @@ export default class PostStream extends Component {
setTimeout(() => this.scrollListener.start());
}
onremove() {
onremove(vnode) {
super.onremove(vnode);
this.scrollListener.stop();
clearTimeout(this.calculatePositionTimeout);
}

View File

@@ -90,7 +90,9 @@ export default class PostStreamScrubber extends Component {
);
}
onupdate() {
onupdate(vnode) {
super.onupdate(vnode);
if (this.stream.forceUpdateScrubber) {
this.stream.forceUpdateScrubber = false;
this.stream.loadPromise.then(() => this.updateScrubberValues({ animate: true, forceHeightChange: true }));
@@ -142,7 +144,9 @@ export default class PostStreamScrubber extends Component {
this.stream.loadPromise.then(() => this.updateScrubberValues({ animate: false, forceHeightChange: true }));
}
onremove() {
onremove(vnode) {
super.onremove(vnode);
this.scrollListener.stop();
$(window).off('resize', this.handlers.onresize);

View File

@@ -123,7 +123,9 @@ export default class Search extends Component {
this.element.querySelector('.Search-results').style['max-height'] = `${maxHeight}px`;
}
onupdate() {
onupdate(vnode) {
super.onupdate(vnode);
// Highlight the item that is currently selected.
this.setIndex(this.getCurrentNumericIndex());
@@ -200,7 +202,9 @@ export default class Search extends Component {
window.addEventListener('resize', this.updateMaxHeightHandler);
}
onremove() {
onremove(vnode) {
super.onremove(vnode);
window.removeEventListener('resize', this.updateMaxHeightHandler);
}