mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Add init hook as a way to effectively monkey patch constructors
Related to #246
This commit is contained in:
@@ -128,12 +128,12 @@ export default class DiscussionPage extends Page {
|
|||||||
// component for the first time on page load, then any calls to m.redraw
|
// component for the first time on page load, then any calls to m.redraw
|
||||||
// will be ineffective and thus any configs (scroll code) will be run
|
// will be ineffective and thus any configs (scroll code) will be run
|
||||||
// before stuff is drawn to the page.
|
// before stuff is drawn to the page.
|
||||||
setTimeout(this.init.bind(this, preloadedDiscussion));
|
setTimeout(this.show.bind(this, preloadedDiscussion));
|
||||||
} else {
|
} else {
|
||||||
const params = this.requestParams();
|
const params = this.requestParams();
|
||||||
|
|
||||||
app.store.find('discussions', m.route.param('id').split('-')[0], params)
|
app.store.find('discussions', m.route.param('id').split('-')[0], params)
|
||||||
.then(this.init.bind(this));
|
.then(this.show.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
m.lazyRedraw();
|
m.lazyRedraw();
|
||||||
@@ -156,7 +156,7 @@ export default class DiscussionPage extends Page {
|
|||||||
*
|
*
|
||||||
* @param {Discussion} discussion
|
* @param {Discussion} discussion
|
||||||
*/
|
*/
|
||||||
init(discussion) {
|
show(discussion) {
|
||||||
this.discussion = discussion;
|
this.discussion = discussion;
|
||||||
|
|
||||||
app.setTitle(discussion.title());
|
app.setTitle(discussion.title());
|
||||||
|
@@ -38,7 +38,7 @@ class PostStream extends mixin(Component, evented) {
|
|||||||
this.loadPageTimeouts = {};
|
this.loadPageTimeouts = {};
|
||||||
this.pagesLoading = 0;
|
this.pagesLoading = 0;
|
||||||
|
|
||||||
this.init(this.props.includedPosts);
|
this.show(this.props.includedPosts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,7 +153,7 @@ class PostStream extends mixin(Component, evented) {
|
|||||||
*
|
*
|
||||||
* @param {Post[]} posts
|
* @param {Post[]} posts
|
||||||
*/
|
*/
|
||||||
init(posts) {
|
show(posts) {
|
||||||
this.visibleStart = posts.length ? this.discussion.postIds().indexOf(posts[0].id()) : 0;
|
this.visibleStart = posts.length ? this.discussion.postIds().indexOf(posts[0].id()) : 0;
|
||||||
this.visibleEnd = this.visibleStart + posts.length;
|
this.visibleEnd = this.visibleStart + posts.length;
|
||||||
}
|
}
|
||||||
@@ -421,7 +421,7 @@ class PostStream extends mixin(Component, evented) {
|
|||||||
return app.store.find('posts', {
|
return app.store.find('posts', {
|
||||||
filter: {discussion: this.discussion.id()},
|
filter: {discussion: this.discussion.id()},
|
||||||
page: {near: number}
|
page: {near: number}
|
||||||
}).then(this.init.bind(this));
|
}).then(this.show.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -442,7 +442,7 @@ class PostStream extends mixin(Component, evented) {
|
|||||||
|
|
||||||
this.reset(start, end);
|
this.reset(start, end);
|
||||||
|
|
||||||
return this.loadRange(start, end).then(this.init.bind(this));
|
return this.loadRange(start, end).then(this.show.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -80,8 +80,8 @@ export default class PostsUserPage extends UserPage {
|
|||||||
* Initialize the component with a user, and trigger the loading of their
|
* Initialize the component with a user, and trigger the loading of their
|
||||||
* activity feed.
|
* activity feed.
|
||||||
*/
|
*/
|
||||||
init(user) {
|
show(user) {
|
||||||
super.init(user);
|
super.show(user);
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ export default class SettingsPage extends UserPage {
|
|||||||
constructor(...args) {
|
constructor(...args) {
|
||||||
super(...args);
|
super(...args);
|
||||||
|
|
||||||
this.init(app.session.user);
|
this.show(app.session.user);
|
||||||
app.setTitle(app.trans('core.settings'));
|
app.setTitle(app.trans('core.settings'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -71,7 +71,7 @@ export default class UserPage extends Page {
|
|||||||
* @param {User} user
|
* @param {User} user
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
init(user) {
|
show(user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
app.setTitle(user.username());
|
app.setTitle(user.username());
|
||||||
@@ -90,13 +90,13 @@ export default class UserPage extends Page {
|
|||||||
|
|
||||||
app.store.all('users').some(user => {
|
app.store.all('users').some(user => {
|
||||||
if (user.username().toLowerCase() === lowercaseUsername && user.joinTime()) {
|
if (user.username().toLowerCase() === lowercaseUsername && user.joinTime()) {
|
||||||
this.init(user);
|
this.show(user);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.user) {
|
if (!this.user) {
|
||||||
app.store.find('users', username).then(this.init.bind(this));
|
app.store.find('users', username).then(this.show.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,6 +53,16 @@ export default class Component {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
this.element = null;
|
this.element = null;
|
||||||
|
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the component is constructed.
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user