From 33dd5fff3696792ef20939dc3ffc784c65b805ec Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 13 Oct 2015 16:55:56 +1030 Subject: [PATCH] Initialise component state in init() instead of constructor This allows component state to be overridden via monkey-patch. ref #246 --- js/admin/src/components/AppearancePage.js | 4 +--- js/admin/src/components/EditCustomCssModal.js | 4 +--- js/admin/src/components/EditGroupModal.js | 4 +--- js/admin/src/components/PermissionGrid.js | 4 +--- js/forum/src/components/AvatarEditor.js | 4 +--- js/forum/src/components/ChangeEmailModal.js | 4 ++-- js/forum/src/components/CommentPost.js | 4 ++-- js/forum/src/components/Composer.js | 4 +--- js/forum/src/components/ComposerBody.js | 4 +--- js/forum/src/components/DiscussionComposer.js | 4 ++-- js/forum/src/components/DiscussionList.js | 4 +--- js/forum/src/components/DiscussionListItem.js | 4 +--- js/forum/src/components/DiscussionPage.js | 4 ++-- js/forum/src/components/DiscussionsUserPage.js | 4 ++-- js/forum/src/components/EditPostComposer.js | 4 ++-- js/forum/src/components/EditUserModal.js | 4 ++-- js/forum/src/components/ForgotPasswordModal.js | 4 ++-- js/forum/src/components/IndexPage.js | 4 ++-- js/forum/src/components/LogInModal.js | 4 ++-- js/forum/src/components/NotificationGrid.js | 4 +--- js/forum/src/components/NotificationList.js | 4 +--- js/forum/src/components/NotificationsDropdown.js | 4 ++-- js/forum/src/components/NotificationsPage.js | 4 ++-- js/forum/src/components/Page.js | 4 +--- js/forum/src/components/Post.js | 4 +--- js/forum/src/components/PostStream.js | 8 ++++---- js/forum/src/components/PostStreamScrubber.js | 4 +--- js/forum/src/components/PostUser.js | 4 +--- js/forum/src/components/PostsUserPage.js | 4 ++-- js/forum/src/components/ReplyComposer.js | 4 ++-- js/forum/src/components/Search.js | 4 +--- js/forum/src/components/SettingsPage.js | 4 ++-- js/forum/src/components/SignUpModal.js | 4 ++-- js/forum/src/components/TextEditor.js | 4 +--- js/forum/src/components/UserBio.js | 4 +--- js/forum/src/components/UserPage.js | 4 ++-- js/forum/src/components/WelcomeHero.js | 4 +--- js/lib/components/AlertManager.js | 4 +--- js/lib/components/Checkbox.js | 4 +--- js/lib/components/Modal.js | 4 +--- js/lib/components/ModalManager.js | 4 +--- 41 files changed, 61 insertions(+), 107 deletions(-) diff --git a/js/admin/src/components/AppearancePage.js b/js/admin/src/components/AppearancePage.js index 176428f1b..4ee74a6e5 100644 --- a/js/admin/src/components/AppearancePage.js +++ b/js/admin/src/components/AppearancePage.js @@ -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'); diff --git a/js/admin/src/components/EditCustomCssModal.js b/js/admin/src/components/EditCustomCssModal.js index ed3f28e39..375ddb3aa 100644 --- a/js/admin/src/components/EditCustomCssModal.js +++ b/js/admin/src/components/EditCustomCssModal.js @@ -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 || ''); } diff --git a/js/admin/src/components/EditGroupModal.js b/js/admin/src/components/EditGroupModal.js index 6d148e9ac..ce84b571c 100644 --- a/js/admin/src/components/EditGroupModal.js +++ b/js/admin/src/components/EditGroupModal.js @@ -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() || ''); diff --git a/js/admin/src/components/PermissionGrid.js b/js/admin/src/components/PermissionGrid.js index f50c975b8..e58ff801f 100644 --- a/js/admin/src/components/PermissionGrid.js +++ b/js/admin/src/components/PermissionGrid.js @@ -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(); } diff --git a/js/forum/src/components/AvatarEditor.js b/js/forum/src/components/AvatarEditor.js index f5f665f84..718c2b3a8 100644 --- a/js/forum/src/components/AvatarEditor.js +++ b/js/forum/src/components/AvatarEditor.js @@ -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. * diff --git a/js/forum/src/components/ChangeEmailModal.js b/js/forum/src/components/ChangeEmailModal.js index 4c1d25420..14f10f740 100644 --- a/js/forum/src/components/ChangeEmailModal.js +++ b/js/forum/src/components/ChangeEmailModal.js @@ -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. diff --git a/js/forum/src/components/CommentPost.js b/js/forum/src/components/CommentPost.js index cc21e9b12..5e775f176 100644 --- a/js/forum/src/components/CommentPost.js +++ b/js/forum/src/components/CommentPost.js @@ -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 diff --git a/js/forum/src/components/Composer.js b/js/forum/src/components/Composer.js index 4eae2a375..b35fbe187 100644 --- a/js/forum/src/components/Composer.js +++ b/js/forum/src/components/Composer.js @@ -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. * diff --git a/js/forum/src/components/ComposerBody.js b/js/forum/src/components/ComposerBody.js index 46ebc7b2e..2a1404104 100644 --- a/js/forum/src/components/ComposerBody.js +++ b/js/forum/src/components/ComposerBody.js @@ -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. * diff --git a/js/forum/src/components/DiscussionComposer.js b/js/forum/src/components/DiscussionComposer.js index e361c3e66..a8230b2bf 100644 --- a/js/forum/src/components/DiscussionComposer.js +++ b/js/forum/src/components/DiscussionComposer.js @@ -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. diff --git a/js/forum/src/components/DiscussionList.js b/js/forum/src/components/DiscussionList.js index fdce20c09..6b892b71b 100644 --- a/js/forum/src/components/DiscussionList.js +++ b/js/forum/src/components/DiscussionList.js @@ -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. * diff --git a/js/forum/src/components/DiscussionListItem.js b/js/forum/src/components/DiscussionListItem.js index caddb8d26..a7b9bde56 100644 --- a/js/forum/src/components/DiscussionListItem.js +++ b/js/forum/src/components/DiscussionListItem.js @@ -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. diff --git a/js/forum/src/components/DiscussionPage.js b/js/forum/src/components/DiscussionPage.js index df815c252..7f0975348 100644 --- a/js/forum/src/components/DiscussionPage.js +++ b/js/forum/src/components/DiscussionPage.js @@ -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. diff --git a/js/forum/src/components/DiscussionsUserPage.js b/js/forum/src/components/DiscussionsUserPage.js index ca42cb2d5..238b32e6c 100644 --- a/js/forum/src/components/DiscussionsUserPage.js +++ b/js/forum/src/components/DiscussionsUserPage.js @@ -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')); } diff --git a/js/forum/src/components/EditPostComposer.js b/js/forum/src/components/EditPostComposer.js index de9827c5e..8eaacdb33 100644 --- a/js/forum/src/components/EditPostComposer.js +++ b/js/forum/src/components/EditPostComposer.js @@ -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)); diff --git a/js/forum/src/components/EditUserModal.js b/js/forum/src/components/EditUserModal.js index a1340ab23..8d963a9db 100644 --- a/js/forum/src/components/EditUserModal.js +++ b/js/forum/src/components/EditUserModal.js @@ -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; diff --git a/js/forum/src/components/ForgotPasswordModal.js b/js/forum/src/components/ForgotPasswordModal.js index e080d3965..586ef26c3 100644 --- a/js/forum/src/components/ForgotPasswordModal.js +++ b/js/forum/src/components/ForgotPasswordModal.js @@ -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. diff --git a/js/forum/src/components/IndexPage.js b/js/forum/src/components/IndexPage.js index a84aff7e7..c48fb7020 100644 --- a/js/forum/src/components/IndexPage.js +++ b/js/forum/src/components/IndexPage.js @@ -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 diff --git a/js/forum/src/components/LogInModal.js b/js/forum/src/components/LogInModal.js index a1bac124c..8b824379f 100644 --- a/js/forum/src/components/LogInModal.js +++ b/js/forum/src/components/LogInModal.js @@ -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. diff --git a/js/forum/src/components/NotificationGrid.js b/js/forum/src/components/NotificationGrid.js index 2806fb99e..2ad9422b3 100644 --- a/js/forum/src/components/NotificationGrid.js +++ b/js/forum/src/components/NotificationGrid.js @@ -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. * diff --git a/js/forum/src/components/NotificationList.js b/js/forum/src/components/NotificationList.js index 7f6f7a410..84843ec81 100644 --- a/js/forum/src/components/NotificationList.js +++ b/js/forum/src/components/NotificationList.js @@ -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. * diff --git a/js/forum/src/components/NotificationsDropdown.js b/js/forum/src/components/NotificationsDropdown.js index ebe5ba1b9..e2fe48ce6 100644 --- a/js/forum/src/components/NotificationsDropdown.js +++ b/js/forum/src/components/NotificationsDropdown.js @@ -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. diff --git a/js/forum/src/components/NotificationsPage.js b/js/forum/src/components/NotificationsPage.js index f898b0662..3364d5d27 100644 --- a/js/forum/src/components/NotificationsPage.js +++ b/js/forum/src/components/NotificationsPage.js @@ -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'); diff --git a/js/forum/src/components/Page.js b/js/forum/src/components/Page.js index 409f59a75..30df93ebf 100644 --- a/js/forum/src/components/Page.js +++ b/js/forum/src/components/Page.js @@ -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; diff --git a/js/forum/src/components/Post.js b/js/forum/src/components/Post.js index 240acf8ff..ba16bf0bf 100644 --- a/js/forum/src/components/Post.js +++ b/js/forum/src/components/Post.js @@ -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. diff --git a/js/forum/src/components/PostStream.js b/js/forum/src/components/PostStream.js index 860232493..19b70a70c 100644 --- a/js/forum/src/components/PostStream.js +++ b/js/forum/src/components/PostStream.js @@ -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; diff --git a/js/forum/src/components/PostStreamScrubber.js b/js/forum/src/components/PostStreamScrubber.js index 3be294872..e849df409 100644 --- a/js/forum/src/components/PostStreamScrubber.js +++ b/js/forum/src/components/PostStreamScrubber.js @@ -15,9 +15,7 @@ import formatNumber from 'flarum/utils/formatNumber'; * - `className` */ export default class PostStreamScrubber extends Component { - constructor(...args) { - super(...args); - + init() { this.handlers = {}; /** diff --git a/js/forum/src/components/PostUser.js b/js/forum/src/components/PostUser.js index 3df0600bb..071c333ed 100644 --- a/js/forum/src/components/PostUser.js +++ b/js/forum/src/components/PostUser.js @@ -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. * diff --git a/js/forum/src/components/PostsUserPage.js b/js/forum/src/components/PostsUserPage.js index 67eb1300c..856e67106 100644 --- a/js/forum/src/components/PostsUserPage.js +++ b/js/forum/src/components/PostsUserPage.js @@ -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. diff --git a/js/forum/src/components/ReplyComposer.js b/js/forum/src/components/ReplyComposer.js index 72d70c133..e23a62882 100644 --- a/js/forum/src/components/ReplyComposer.js +++ b/js/forum/src/components/ReplyComposer.js @@ -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')); diff --git a/js/forum/src/components/Search.js b/js/forum/src/components/Search.js index 854c8d88d..7ce91f99a 100644 --- a/js/forum/src/components/Search.js +++ b/js/forum/src/components/Search.js @@ -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. * diff --git a/js/forum/src/components/SettingsPage.js b/js/forum/src/components/SettingsPage.js index 3a4649c62..4cc39ac0b 100644 --- a/js/forum/src/components/SettingsPage.js +++ b/js/forum/src/components/SettingsPage.js @@ -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')); diff --git a/js/forum/src/components/SignUpModal.js b/js/forum/src/components/SignUpModal.js index c81f2eb6d..5472a7d2b 100644 --- a/js/forum/src/components/SignUpModal.js +++ b/js/forum/src/components/SignUpModal.js @@ -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. diff --git a/js/forum/src/components/TextEditor.js b/js/forum/src/components/TextEditor.js index 1feaa7de1..e68d442c9 100644 --- a/js/forum/src/components/TextEditor.js +++ b/js/forum/src/components/TextEditor.js @@ -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. * diff --git a/js/forum/src/components/UserBio.js b/js/forum/src/components/UserBio.js index 126762985..e8ebdab3f 100644 --- a/js/forum/src/components/UserBio.js +++ b/js/forum/src/components/UserBio.js @@ -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. * diff --git a/js/forum/src/components/UserPage.js b/js/forum/src/components/UserPage.js index 795bea342..028fce827 100644 --- a/js/forum/src/components/UserPage.js +++ b/js/forum/src/components/UserPage.js @@ -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. diff --git a/js/forum/src/components/WelcomeHero.js b/js/forum/src/components/WelcomeHero.js index c51dd45da..856cd048a 100644 --- a/js/forum/src/components/WelcomeHero.js +++ b/js/forum/src/components/WelcomeHero.js @@ -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'); } diff --git a/js/lib/components/AlertManager.js b/js/lib/components/AlertManager.js index 491709ec2..f0d8b2a48 100644 --- a/js/lib/components/AlertManager.js +++ b/js/lib/components/AlertManager.js @@ -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. * diff --git a/js/lib/components/Checkbox.js b/js/lib/components/Checkbox.js index 3ec3a15c1..6e02a42d3 100644 --- a/js/lib/components/Checkbox.js +++ b/js/lib/components/Checkbox.js @@ -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. * diff --git a/js/lib/components/Modal.js b/js/lib/components/Modal.js index 1d5b81493..84f56082b 100644 --- a/js/lib/components/Modal.js +++ b/js/lib/components/Modal.js @@ -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. * diff --git a/js/lib/components/ModalManager.js b/js/lib/components/ModalManager.js index a29f4c501..35eb5a445 100644 --- a/js/lib/components/ModalManager.js +++ b/js/lib/components/ModalManager.js @@ -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; }