Massive JavaScript cleanup

- Use JSX for templates
- Docblock/comment everything
- Mostly passes ESLint (still some work to do)
- Lots of renaming, refactoring, etc.

CSS hasn't been updated yet.
This commit is contained in:
Toby Zerner
2015-07-15 14:00:11 +09:30
parent 4480e0a83f
commit ab6c03c0cc
220 changed files with 9785 additions and 5919 deletions

View File

@ -0,0 +1,18 @@
import humanTimeUtil from 'flarum/utils/humanTime';
function updateHumanTimes() {
$('[data-humantime]').each(function() {
const $this = $(this);
const ago = humanTimeUtil($this.attr('datetime'));
$this.html(ago);
});
}
/**
* The `humanTime` initializer sets up a loop every 1 second to update
* timestamps rendered with the `humanTime` helper.
*/
export default function humanTime() {
setInterval(updateHumanTimes, 1000);
}

View File

@ -1,9 +1,17 @@
export default function(app) {
app.store.pushPayload({data: app.preload.data});
app.forum = app.store.getById('forums', 1);
import Session from 'flarum/Session';
if (app.preload.session) {
app.session.token(app.preload.session.token);
app.session.user(app.store.getById('users', app.preload.session.userId));
}
/**
* The `session` initializer creates the application session and preloads it
* with data that has been set on the application's `preload` property.
*
* `app.preload.session` should be the same as the response from the /api/token
* endpoint: it should contain `token` and `userId` keys.
*
* @param {App} app
*/
export default function session(app) {
app.session = new Session(
app.preload.session.token,
app.store.getById('users', app.preload.session.userId)
);
}

View File

@ -1,5 +0,0 @@
import Session from 'flarum/session';
export default function(app) {
app.session = new Session();
}

View File

@ -1,16 +1,22 @@
import Store from 'flarum/store';
import Forum from 'flarum/models/forum';
import User from 'flarum/models/user';
import Discussion from 'flarum/models/discussion';
import Post from 'flarum/models/post';
import Group from 'flarum/models/group';
import Activity from 'flarum/models/activity';
import Notification from 'flarum/models/notification';
import Store from 'flarum/Store';
import Forum from 'flarum/models/Forum';
import User from 'flarum/models/User';
import Discussion from 'flarum/models/Discussion';
import Post from 'flarum/models/Post';
import Group from 'flarum/models/Group';
import Activity from 'flarum/models/Activity';
import Notification from 'flarum/models/Notification';
export default function(app) {
app.store = new Store();
app.store.models = {
/**
* The `store` initializer creates the application's data store and registers
* the default resource types to their models. It then preloads any data on the
* application's `preload` property into the store. Finally, it sets the
* application's `forum` instance to the one that was preloaded.
*
* @param {App} app
*/
export default function store(app) {
app.store = new Store({
forums: Forum,
users: User,
discussions: Discussion,
@ -18,5 +24,9 @@ export default function(app) {
groups: Group,
activity: Activity,
notifications: Notification
};
});
app.store.pushPayload({data: app.preload.data});
app.forum = app.store.getById('forums', 1);
}

View File

@ -1,10 +0,0 @@
import humanTime from 'flarum/utils/human-time';
export default function(app) {
setInterval(function() {
$('[data-humantime]').each(function() {
var $this = $(this);
$this.html(humanTime($this.attr('datetime')));
});
}, 1000);
}