Clean up, don't use mixin

PhpStorm/WebStorm doesn't like the mixin syntax, and it's clearer to just use Object.assign.
This commit is contained in:
Toby Zerner 2015-10-13 16:57:18 +10:30
parent 94a6ddead3
commit 79ec0ef0ec
9 changed files with 44 additions and 27 deletions

View File

@ -143,7 +143,7 @@ export default class IndexPage extends Page {
*/
sidebarItems() {
const items = new ItemList();
const canStartDiscussion = app.forum.canStartDiscussion() || !app.session.user;
const canStartDiscussion = app.forum.attribute('canStartDiscussion') || !app.session.user;
items.add('newDiscussion',
Button.component({

View File

@ -34,7 +34,7 @@ export default class Component {
* @param {Array|Object} children
* @public
*/
constructor(props = {}, children) {
constructor(props = {}, children = null) {
if (children) props.children = children;
this.constructor.initProps(props);
@ -158,6 +158,7 @@ export default class Component {
*
* @see https://lhorie.github.io/mithril/mithril.component.html
* @param {Object} [props] Properties to set on the component
* @param children
* @return {Object} The Mithril component object
* @property {function} controller
* @property {function} view
@ -165,7 +166,7 @@ export default class Component {
* @property {Object} props The props that were passed to the component
* @public
*/
static component(props = {}, children) {
static component(props = {}, children = null) {
const componentProps = Object.assign({}, props);
if (children) componentProps.children = children;

View File

@ -10,7 +10,7 @@ export default class Model {
* @param {Store} store The data store that this model should be persisted to.
* @public
*/
constructor(data = {}, store) {
constructor(data = {}, store = null) {
/**
* The resource object from the API.
*

View File

@ -5,7 +5,9 @@ import ItemList from 'flarum/utils/ItemList';
import { slug } from 'flarum/utils/string';
import Badge from 'flarum/components/Badge';
export default class Discussion extends mixin(Model, {
export default class Discussion extends Model {}
Object.assign(Discussion.prototype, {
title: Model.attribute('title'),
slug: computed('title', slug),
@ -35,8 +37,8 @@ export default class Discussion extends mixin(Model, {
canReply: Model.attribute('canReply'),
canRename: Model.attribute('canRename'),
canHide: Model.attribute('canHide'),
canDelete: Model.attribute('canDelete')
}) {
canDelete: Model.attribute('canDelete'),
/**
* Remove a post from the discussion's posts relationship.
*
@ -55,7 +57,7 @@ export default class Discussion extends mixin(Model, {
}
});
}
}
},
/**
* Get the estimated number of unread posts in this discussion for the current
@ -72,7 +74,7 @@ export default class Discussion extends mixin(Model, {
}
return 0;
}
},
/**
* Get the Badge components that apply to this discussion.
@ -88,7 +90,7 @@ export default class Discussion extends mixin(Model, {
}
return items;
}
},
/**
* Get a list of all of the post IDs in this discussion.
@ -99,4 +101,6 @@ export default class Discussion extends mixin(Model, {
postIds() {
return this.data.relationships.posts.data.map(link => link.id);
}
}
});
export default Discussion;

View File

@ -1,9 +1,7 @@
import Model from 'flarum/Model';
import mixin from 'flarum/utils/mixin';
export default class Forum extends mixin(Model, {
canStartDiscussion: Model.attribute('canStartDiscussion')
}) {
export default class Forum extends Model {
apiEndpoint() {
return '/forum';
}

View File

@ -1,12 +1,14 @@
import Model from 'flarum/Model';
import mixin from 'flarum/utils/mixin';
class Group extends mixin(Model, {
class Group extends Model {}
Object.assign(Group.prototype, {
nameSingular: Model.attribute('nameSingular'),
namePlural: Model.attribute('namePlural'),
color: Model.attribute('color'),
icon: Model.attribute('icon')
}) {}
});
Group.ADMINISTRATOR_ID = '1';
Group.GUEST_ID = '2';

View File

@ -2,7 +2,9 @@ import Model from 'flarum/Model';
import mixin from 'flarum/utils/mixin';
import computed from 'flarum/utils/computed';
export default class Notification extends mixin(Model, {
export default class Notification extends Model {}
Object.assign(Notification.prototype, {
contentType: Model.attribute('contentType'),
subjectId: Model.attribute('subjectId'),
content: Model.attribute('content'),
@ -15,4 +17,6 @@ export default class Notification extends mixin(Model, {
user: Model.hasOne('user'),
sender: Model.hasOne('sender'),
subject: Model.hasOne('subject')
}) {}
});
export default Notification;

View File

@ -3,7 +3,9 @@ import mixin from 'flarum/utils/mixin';
import computed from 'flarum/utils/computed';
import { getPlainContent } from 'flarum/utils/string';
export default class Post extends mixin(Model, {
export default class Post extends Model {}
Object.assign(Post.prototype, {
number: Model.attribute('number'),
discussion: Model.hasOne('discussion'),
@ -24,4 +26,6 @@ export default class Post extends mixin(Model, {
canEdit: Model.attribute('canEdit'),
canDelete: Model.attribute('canDelete')
}) {}
});
export default Post;

View File

@ -7,7 +7,9 @@ import ItemList from 'flarum/utils/ItemList';
import computed from 'flarum/utils/computed';
import GroupBadge from 'flarum/components/GroupBadge';
export default class User extends mixin(Model, {
export default class User extends Model {}
Object.assign(User.prototype, {
username: Model.attribute('username'),
email: Model.attribute('email'),
isActivated: Model.attribute('isActivated'),
@ -45,8 +47,8 @@ export default class User extends mixin(Model, {
}
return '#' + stringToColor(username);
})
}) {
}),
/**
* Check whether or not the user has been seen in the last 5 minutes.
*
@ -55,7 +57,7 @@ export default class User extends mixin(Model, {
*/
isOnline() {
return this.lastSeenTime() > moment().subtract(5, 'minutes').toDate();
}
},
/**
* Get the Badge components that apply to this user.
@ -73,7 +75,7 @@ export default class User extends mixin(Model, {
}
return items;
}
},
/**
* Calculate the dominant color of the user's avatar. The dominant color will
@ -92,7 +94,7 @@ export default class User extends mixin(Model, {
m.redraw();
};
image.src = this.avatarUrl();
}
},
/**
* Update the user's preferences.
@ -107,4 +109,6 @@ export default class User extends mixin(Model, {
return this.save({preferences});
}
}
});
export default User;