mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 14:49:57 +08:00
Initialise component state in init() instead of constructor
This allows component state to be overridden via monkey-patch. ref #246
This commit is contained in:
@ -5,9 +5,7 @@ import EditCustomCssModal from 'flarum/components/EditCustomCssModal';
|
||||
import saveSettings from 'flarum/utils/saveSettings';
|
||||
|
||||
export default class AppearancePage extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
this.primaryColor = m.prop(app.settings.theme_primary_color);
|
||||
this.secondaryColor = m.prop(app.settings.theme_secondary_color);
|
||||
this.darkMode = m.prop(app.settings.theme_dark_mode === '1');
|
||||
|
@ -3,9 +3,7 @@ import Button from 'flarum/components/Button';
|
||||
import saveSettings from 'flarum/utils/saveSettings';
|
||||
|
||||
export default class EditCustomCssModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
this.customLess = m.prop(app.settings.custom_less || '');
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,7 @@ import Group from 'flarum/models/Group';
|
||||
* to create or edit a group.
|
||||
*/
|
||||
export default class EditGroupModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
this.group = this.props.group || app.store.createRecord('groups');
|
||||
|
||||
this.nameSingular = m.prop(this.group.nameSingular() || '');
|
||||
|
@ -6,9 +6,7 @@ import ItemList from 'flarum/utils/ItemList';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
|
||||
export default class PermissionGrid extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
this.permissions = this.permissionItems().toArray();
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,7 @@ import LoadingIndicator from 'flarum/components/LoadingIndicator';
|
||||
* - `user`
|
||||
*/
|
||||
export default class AvatarEditor extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Whether or not an avatar upload is in progress.
|
||||
*
|
||||
|
@ -6,8 +6,8 @@ import Button from 'flarum/components/Button';
|
||||
* to change their email address.
|
||||
*/
|
||||
export default class ChangeEmailModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* Whether or not the email has been changed successfully.
|
||||
|
@ -21,8 +21,8 @@ import Button from 'flarum/components/Button';
|
||||
* - `post`
|
||||
*/
|
||||
export default class CommentPost extends Post {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* If the post has been hidden, then this flag determines whether or not its
|
||||
|
@ -11,9 +11,7 @@ import computed from 'flarum/utils/computed';
|
||||
* `show`, `hide`, `close`, `minimize`, `fullScreen`, and `exitFullScreen`.
|
||||
*/
|
||||
class Composer extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* The composer's current position.
|
||||
*
|
||||
|
@ -22,9 +22,7 @@ import ItemList from 'flarum/utils/ItemList';
|
||||
* @abstract
|
||||
*/
|
||||
export default class ComposerBody extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Whether or not the component is loading.
|
||||
*
|
||||
|
@ -13,8 +13,8 @@ import extractText from 'flarum/utils/extractText';
|
||||
* - `titlePlaceholder`
|
||||
*/
|
||||
export default class DiscussionComposer extends ComposerBody {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* The value of the title input.
|
||||
|
@ -13,9 +13,7 @@ import Placeholder from 'flarum/components/Placeholder';
|
||||
* to send along in the API request to get discussion results.
|
||||
*/
|
||||
export default class DiscussionList extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Whether or not discussion results are loading.
|
||||
*
|
||||
|
@ -25,9 +25,7 @@ import classList from 'flarum/utils/classList';
|
||||
* - `params`
|
||||
*/
|
||||
export default class DiscussionListItem extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Set up a subtree retainer so that the discussion will not be redrawn
|
||||
* unless new data comes in.
|
||||
|
@ -13,8 +13,8 @@ import DiscussionControls from 'flarum/utils/DiscussionControls';
|
||||
* the discussion list pane, the hero, the posts, and the sidebar.
|
||||
*/
|
||||
export default class DiscussionPage extends Page {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* The discussion that is being viewed.
|
||||
|
@ -6,8 +6,8 @@ import DiscussionList from 'flarum/components/DiscussionList';
|
||||
* page.
|
||||
*/
|
||||
export default class DiscussionsUserPage extends UserPage {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
this.loadUser(m.route.param('username'));
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ import icon from 'flarum/helpers/icon';
|
||||
* - `post`
|
||||
*/
|
||||
export default class EditPostComposer extends ComposerBody {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
this.editor.props.preview = () => {
|
||||
m.route(app.route.post(this.props.post));
|
||||
|
@ -8,8 +8,8 @@ import extractText from 'flarum/utils/extractText';
|
||||
* The `EditUserModal` component displays a modal dialog with a login form.
|
||||
*/
|
||||
export default class EditUserModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
const user = this.props.user;
|
||||
|
||||
|
@ -12,8 +12,8 @@ import extractText from 'flarum/utils/extractText';
|
||||
* - `email`
|
||||
*/
|
||||
export default class ForgotPasswordModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* The value of the email input.
|
||||
|
@ -17,8 +17,8 @@ import SelectDropdown from 'flarum/components/SelectDropdown';
|
||||
* hero, the sidebar, and the discussion list.
|
||||
*/
|
||||
export default class IndexPage extends Page {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
// If the user is returning from a discussion page, then take note of which
|
||||
// discussion they have just visited. After the view is rendered, we will
|
||||
|
@ -15,8 +15,8 @@ import extractText from 'flarum/utils/extractText';
|
||||
* - `password`
|
||||
*/
|
||||
export default class LogInModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* The value of the email input.
|
||||
|
@ -12,9 +12,7 @@ import ItemList from 'flarum/utils/ItemList';
|
||||
* - `user`
|
||||
*/
|
||||
export default class NotificationGrid extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Information about the available notification methods.
|
||||
*
|
||||
|
@ -9,9 +9,7 @@ import Discussion from 'flarum/models/Discussion';
|
||||
* notifications, grouped by discussion.
|
||||
*/
|
||||
export default class NotificationList extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Whether or not the notifications are loading.
|
||||
*
|
||||
|
@ -13,8 +13,8 @@ export default class NotificationsDropdown extends Dropdown {
|
||||
super.initProps(props);
|
||||
}
|
||||
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* Whether or not the notifications dropdown is visible.
|
||||
|
@ -6,8 +6,8 @@ import NotificationList from 'flarum/components/NotificationList';
|
||||
* used on mobile devices where the notifications dropdown is within the drawer.
|
||||
*/
|
||||
export default class NotificationsPage extends Page {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
app.history.push('notifications');
|
||||
|
||||
|
@ -6,9 +6,7 @@ import Component from 'flarum/Component';
|
||||
* @abstract
|
||||
*/
|
||||
export default class Page extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
app.previous = app.current;
|
||||
app.current = this;
|
||||
|
||||
|
@ -17,9 +17,7 @@ import ItemList from 'flarum/utils/ItemList';
|
||||
* @abstract
|
||||
*/
|
||||
export default class Post extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Set up a subtree retainer so that the post will not be redrawn
|
||||
* unless new data comes in.
|
||||
|
@ -15,10 +15,8 @@ import ReplyPlaceholder from 'flarum/components/ReplyPlaceholder';
|
||||
* - `discussion`
|
||||
* - `includedPosts`
|
||||
*/
|
||||
class PostStream extends mixin(Component, evented) {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
class PostStream extends Component {
|
||||
init() {
|
||||
/**
|
||||
* The discussion to display the post stream for.
|
||||
*
|
||||
@ -585,4 +583,6 @@ class PostStream extends mixin(Component, evented) {
|
||||
*/
|
||||
PostStream.loadCount = 20;
|
||||
|
||||
Object.assign(PostStream.prototype, evented);
|
||||
|
||||
export default PostStream;
|
||||
|
@ -15,9 +15,7 @@ import formatNumber from 'flarum/utils/formatNumber';
|
||||
* - `className`
|
||||
*/
|
||||
export default class PostStreamScrubber extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
this.handlers = {};
|
||||
|
||||
/**
|
||||
|
@ -12,9 +12,7 @@ import listItems from 'flarum/helpers/listItems';
|
||||
* - `post`
|
||||
*/
|
||||
export default class PostUser extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Whether or not the user hover card is visible.
|
||||
*
|
||||
|
@ -8,8 +8,8 @@ import CommentPost from 'flarum/components/CommentPost';
|
||||
* profile.
|
||||
*/
|
||||
export default class PostsUserPage extends UserPage {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* Whether or not the activity feed is currently loading.
|
||||
|
@ -14,8 +14,8 @@ import extractText from 'flarum/utils/extractText';
|
||||
* - `discussion`
|
||||
*/
|
||||
export default class ReplyComposer extends ComposerBody {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
this.editor.props.preview = () => {
|
||||
m.route(app.route.discussion(this.props.discussion, 'reply'));
|
||||
|
@ -17,9 +17,7 @@ import UsersSearchSource from 'flarum/components/UsersSearchSource';
|
||||
* `clearSearch` method on the controller.
|
||||
*/
|
||||
export default class Search extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* The value of the search input.
|
||||
*
|
||||
|
@ -13,8 +13,8 @@ import listItems from 'flarum/helpers/listItems';
|
||||
* the context of their user profile.
|
||||
*/
|
||||
export default class SettingsPage extends UserPage {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
this.show(app.session.user);
|
||||
app.setTitle(app.trans('core.forum.settings_title'));
|
||||
|
@ -16,8 +16,8 @@ import extractText from 'flarum/utils/extractText';
|
||||
* - `token` An email token to sign up with.
|
||||
*/
|
||||
export default class SignUpModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* The value of the username input.
|
||||
|
@ -15,9 +15,7 @@ import Button from 'flarum/components/Button';
|
||||
* - `disabled`
|
||||
*/
|
||||
export default class TextEditor extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* The value of the textarea.
|
||||
*
|
||||
|
@ -8,9 +8,7 @@ import extractText from 'flarum/utils/extractText';
|
||||
* edit it.
|
||||
*/
|
||||
export default class UserBio extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Whether or not the bio is currently being edited.
|
||||
*
|
||||
|
@ -16,8 +16,8 @@ import listItems from 'flarum/helpers/listItems';
|
||||
* @abstract
|
||||
*/
|
||||
export default class UserPage extends Page {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* The user this page is for.
|
||||
|
@ -6,9 +6,7 @@ import Button from 'flarum/components/Button';
|
||||
* forum.
|
||||
*/
|
||||
export default class WelcomeHero extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
this.hidden = localStorage.getItem('welcomeHidden');
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,7 @@ import Alert from 'flarum/components/Alert';
|
||||
* be shown and dismissed.
|
||||
*/
|
||||
export default class AlertManager extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* An array of Alert components which are currently showing.
|
||||
*
|
||||
|
@ -14,9 +14,7 @@ import icon from 'flarum/helpers/icon';
|
||||
* - `children` A text label to display next to the checkbox.
|
||||
*/
|
||||
export default class Checkbox extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* Whether or not the checkbox's value is in the process of being saved.
|
||||
*
|
||||
|
@ -9,9 +9,7 @@ import Button from 'flarum/components/Button';
|
||||
* @abstract
|
||||
*/
|
||||
export default class Modal extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
/**
|
||||
* An alert component to show below the header.
|
||||
*
|
||||
|
@ -7,9 +7,7 @@ import Modal from 'flarum/components/Modal';
|
||||
* overwrite the previous one.
|
||||
*/
|
||||
export default class ModalManager extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
init() {
|
||||
this.showing = false;
|
||||
this.component = null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user