Skip to content

Commit

Permalink
Initialise component state in init() instead of constructor
Browse files Browse the repository at this point in the history
This allows component state to be overridden via monkey-patch. ref #246
  • Loading branch information
tobyzerner committed Oct 13, 2015
1 parent 2ae7392 commit 33dd5ff
Show file tree
Hide file tree
Showing 41 changed files with 61 additions and 107 deletions.
4 changes: 1 addition & 3 deletions js/admin/src/components/AppearancePage.js
Expand Up @@ -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');
Expand Down
4 changes: 1 addition & 3 deletions js/admin/src/components/EditCustomCssModal.js
Expand Up @@ -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 || '');
}

Expand Down
4 changes: 1 addition & 3 deletions js/admin/src/components/EditGroupModal.js
Expand Up @@ -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() || '');
Expand Down
4 changes: 1 addition & 3 deletions js/admin/src/components/PermissionGrid.js
Expand Up @@ -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();
}

Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/AvatarEditor.js
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/ChangeEmailModal.js
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/CommentPost.js
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/Composer.js
Expand Up @@ -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.
*
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/ComposerBody.js
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/DiscussionComposer.js
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/DiscussionList.js
Expand Up @@ -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.
*
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/DiscussionListItem.js
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/DiscussionPage.js
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/DiscussionsUserPage.js
Expand Up @@ -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'));
}
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/EditPostComposer.js
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/EditUserModal.js
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/ForgotPasswordModal.js
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/IndexPage.js
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/LogInModal.js
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/NotificationGrid.js
Expand Up @@ -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.
*
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/NotificationList.js
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/NotificationsDropdown.js
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/NotificationsPage.js
Expand Up @@ -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');

Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/Page.js
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/Post.js
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions js/forum/src/components/PostStream.js
Expand Up @@ -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.
*
Expand Down Expand Up @@ -585,4 +583,6 @@ class PostStream extends mixin(Component, evented) {
*/
PostStream.loadCount = 20;

Object.assign(PostStream.prototype, evented);

export default PostStream;
4 changes: 1 addition & 3 deletions js/forum/src/components/PostStreamScrubber.js
Expand Up @@ -15,9 +15,7 @@ import formatNumber from 'flarum/utils/formatNumber';
* - `className`
*/
export default class PostStreamScrubber extends Component {
constructor(...args) {
super(...args);

init() {
this.handlers = {};

/**
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/PostUser.js
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/PostsUserPage.js
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/ReplyComposer.js
Expand Up @@ -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'));
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/Search.js
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/SettingsPage.js
Expand Up @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions js/forum/src/components/SignUpModal.js
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/TextEditor.js
Expand Up @@ -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.
*
Expand Down
4 changes: 1 addition & 3 deletions js/forum/src/components/UserBio.js
Expand Up @@ -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.
*
Expand Down

0 comments on commit 33dd5ff

Please sign in to comment.