mirror of
https://github.com/flarum/framework.git
synced 2025-02-24 05:55:25 +08:00
Use all Mithril lifecycle stubs (#2847)
This commit is contained in:
parent
45602a83c6
commit
6c2d01a5b8
@ -27,7 +27,9 @@ export default class AdminNav extends Component {
|
|||||||
this.scrollToActive();
|
this.scrollToActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate(vnode) {
|
||||||
|
super.onupdate(vnode);
|
||||||
|
|
||||||
this.scrollToActive();
|
this.scrollToActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,21 @@ export default abstract class Component<T extends ComponentAttrs = ComponentAttr
|
|||||||
this.setAttrs(vnode.attrs);
|
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
|
* 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
|
* 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);
|
$(window).on('beforeunload', this.boundHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
$(window).off('beforeunload', this.boundHandler);
|
$(window).off('beforeunload', this.boundHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ export default class Modal extends Component {
|
|||||||
this.attrs.animateShow(() => this.onready());
|
this.attrs.animateShow(() => this.onready());
|
||||||
}
|
}
|
||||||
|
|
||||||
onbeforeremove() {
|
onbeforeremove(vnode) {
|
||||||
|
super.onbeforeremove(vnode);
|
||||||
|
|
||||||
// If the global modal state currently contains a modal,
|
// If the global modal state currently contains a modal,
|
||||||
// we've just opened up a new one, and accordingly,
|
// we've just opened up a new one, and accordingly,
|
||||||
// we don't need to show a hide animation.
|
// 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) {
|
if (this.bodyClass) {
|
||||||
$('#app').removeClass(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]);
|
this.attrs.composer.editor = this.buildEditor(this.$('.TextEditor-editorContainer')[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate(vnode) {
|
||||||
|
super.onupdate(vnode);
|
||||||
|
|
||||||
const newDisabled = !!this.attrs.disabled;
|
const newDisabled = !!this.attrs.disabled;
|
||||||
|
|
||||||
if (this.disabled !== newDisabled) {
|
if (this.disabled !== newDisabled) {
|
||||||
|
@ -24,7 +24,9 @@ export default class AffixedSidebar extends Component {
|
|||||||
$(window).on('resize', this.boundOnresize).resize();
|
$(window).on('resize', this.boundOnresize).resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
$(window).off('resize', this.boundOnresize);
|
$(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) {
|
if (this.state.position === this.prevPosition) {
|
||||||
// Set the height of the Composer element and its contents on each redraw,
|
// 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.
|
// 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)));
|
.on('mouseup', (this.handlers.onmouseup = this.onmouseup.bind(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
$(window).off('resize', this.handlers.onresize);
|
$(window).off('resize', this.handlers.onresize);
|
||||||
|
|
||||||
$(document).off('mousemove', this.handlers.onmousemove).off('mouseup', this.handlers.onmouseup);
|
$(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);
|
this.updateInterval = setInterval(updatePreview, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
clearInterval(this.updateInterval);
|
clearInterval(this.updateInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,9 @@ export default class DiscussionPage extends Page {
|
|||||||
this.bodyClass = 'App--discussion';
|
this.bodyClass = 'App--discussion';
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
super.onremove();
|
super.onremove(vnode);
|
||||||
|
|
||||||
// If we are indeed navigating away from this discussion, then disable the
|
// 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 list pane. Also, if we're composing a reply to this
|
||||||
// discussion, minimize the composer – unless it's empty, in which case
|
// 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
|
// Save the scroll position so we can restore it when we return to the
|
||||||
// discussion list.
|
// discussion list.
|
||||||
app.cache.scrollTop = $(window).scrollTop();
|
app.cache.scrollTop = $(window).scrollTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
super.onremove();
|
super.onremove(vnode);
|
||||||
|
|
||||||
$('#app').css('min-height', '');
|
$('#app').css('min-height', '');
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,9 @@ export default class NotificationList extends Component {
|
|||||||
this.$scrollParent.on('scroll', this.boundScrollHandler);
|
this.$scrollParent.on('scroll', this.boundScrollHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
this.$scrollParent.off('scroll', this.boundScrollHandler);
|
this.$scrollParent.off('scroll', this.boundScrollHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,9 @@ export default class Post extends Component {
|
|||||||
return this.subtree.needsRebuild();
|
return this.subtree.needsRebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate(vnode) {
|
||||||
|
super.onupdate(vnode);
|
||||||
|
|
||||||
const $actions = this.$('.Post-actions');
|
const $actions = this.$('.Post-actions');
|
||||||
const $controls = this.$('.Post-controls');
|
const $controls = this.$('.Post-controls');
|
||||||
|
|
||||||
|
@ -40,7 +40,9 @@ export default class PostEdited extends Component {
|
|||||||
this.rebuildTooltip();
|
this.rebuildTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate(vnode) {
|
||||||
|
super.onupdate(vnode);
|
||||||
|
|
||||||
this.rebuildTooltip();
|
this.rebuildTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,9 @@ export default class PostStream extends Component {
|
|||||||
return <div className="PostStream">{items}</div>;
|
return <div className="PostStream">{items}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate(vnode) {
|
||||||
|
super.onupdate(vnode);
|
||||||
|
|
||||||
this.triggerScroll();
|
this.triggerScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +122,9 @@ export default class PostStream extends Component {
|
|||||||
setTimeout(() => this.scrollListener.start());
|
setTimeout(() => this.scrollListener.start());
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
this.scrollListener.stop();
|
this.scrollListener.stop();
|
||||||
clearTimeout(this.calculatePositionTimeout);
|
clearTimeout(this.calculatePositionTimeout);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,9 @@ export default class PostStreamScrubber extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate(vnode) {
|
||||||
|
super.onupdate(vnode);
|
||||||
|
|
||||||
if (this.stream.forceUpdateScrubber) {
|
if (this.stream.forceUpdateScrubber) {
|
||||||
this.stream.forceUpdateScrubber = false;
|
this.stream.forceUpdateScrubber = false;
|
||||||
this.stream.loadPromise.then(() => this.updateScrubberValues({ animate: true, forceHeightChange: true }));
|
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 }));
|
this.stream.loadPromise.then(() => this.updateScrubberValues({ animate: false, forceHeightChange: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
this.scrollListener.stop();
|
this.scrollListener.stop();
|
||||||
$(window).off('resize', this.handlers.onresize);
|
$(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`;
|
this.element.querySelector('.Search-results').style['max-height'] = `${maxHeight}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate(vnode) {
|
||||||
|
super.onupdate(vnode);
|
||||||
|
|
||||||
// Highlight the item that is currently selected.
|
// Highlight the item that is currently selected.
|
||||||
this.setIndex(this.getCurrentNumericIndex());
|
this.setIndex(this.getCurrentNumericIndex());
|
||||||
|
|
||||||
@ -200,7 +202,9 @@ export default class Search extends Component {
|
|||||||
window.addEventListener('resize', this.updateMaxHeightHandler);
|
window.addEventListener('resize', this.updateMaxHeightHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
super.onremove(vnode);
|
||||||
|
|
||||||
window.removeEventListener('resize', this.updateMaxHeightHandler);
|
window.removeEventListener('resize', this.updateMaxHeightHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user