mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 11:07:58 +08:00
Use all Mithril lifecycle stubs (#2847)
This commit is contained in:
parent
ceb567779e
commit
d4e3254395
@ -27,7 +27,9 @@ export default class AdminNav extends Component {
|
||||
this.scrollToActive();
|
||||
}
|
||||
|
||||
onupdate() {
|
||||
onupdate(vnode) {
|
||||
super.onupdate(vnode);
|
||||
|
||||
this.scrollToActive();
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,21 @@ export default abstract class Component<T extends ComponentAttrs = ComponentAttr
|
||||
this.setAttrs(vnode.attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
onupdate(vnode: Mithril.VnodeDOM<T, this>) {}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
onbeforeremove(vnode: Mithril.VnodeDOM<T, this>) {}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
onremove(vnode: Mithril.VnodeDOM<T, this>) {}
|
||||
|
||||
/**
|
||||
* Returns a jQuery object for this component's element. If you pass in a
|
||||
* selector string, this method will return a jQuery object, using the current
|
||||
|
@ -28,7 +28,9 @@ export default class ConfirmDocumentUnload extends Component {
|
||||
$(window).on('beforeunload', this.boundHandler);
|
||||
}
|
||||
|
||||
onremove() {
|
||||
onremove(vnode) {
|
||||
super.onremove(vnode);
|
||||
|
||||
$(window).off('beforeunload', this.boundHandler);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,9 @@ export default class Modal extends Component {
|
||||
this.attrs.animateShow(() => this.onready());
|
||||
}
|
||||
|
||||
onbeforeremove() {
|
||||
onbeforeremove(vnode) {
|
||||
super.onbeforeremove(vnode);
|
||||
|
||||
// If the global modal state currently contains a modal,
|
||||
// we've just opened up a new one, and accordingly,
|
||||
// we don't need to show a hide animation.
|
||||
|
@ -54,7 +54,9 @@ export default class Page extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
onremove() {
|
||||
onremove(vnode) {
|
||||
super.onremove(vnode);
|
||||
|
||||
if (this.bodyClass) {
|
||||
$('#app').removeClass(this.bodyClass);
|
||||
}
|
||||
|
@ -54,7 +54,9 @@ export default class TextEditor extends Component {
|
||||
this.attrs.composer.editor = this.buildEditor(this.$('.TextEditor-editorContainer')[0]);
|
||||
}
|
||||
|
||||
onupdate() {
|
||||
onupdate(vnode) {
|
||||
super.onupdate(vnode);
|
||||
|
||||
const newDisabled = !!this.attrs.disabled;
|
||||
|
||||
if (this.disabled !== newDisabled) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -48,7 +48,9 @@ export default class ComposerPostPreview extends Component {
|
||||
this.updateInterval = setInterval(updatePreview, 50);
|
||||
}
|
||||
|
||||
onremove() {
|
||||
onremove(vnode) {
|
||||
super.onremove(vnode);
|
||||
|
||||
clearInterval(this.updateInterval);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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', '');
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
|
||||
|
@ -40,7 +40,9 @@ export default class PostEdited extends Component {
|
||||
this.rebuildTooltip();
|
||||
}
|
||||
|
||||
onupdate() {
|
||||
onupdate(vnode) {
|
||||
super.onupdate(vnode);
|
||||
|
||||
this.rebuildTooltip();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user