[Client] Refactoring

This commit is contained in:
syuilo 2017-03-20 14:49:24 +09:00
parent 431da9e087
commit b6475958d0
19 changed files with 72 additions and 102 deletions

View file

@ -76,8 +76,6 @@
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.user = null;
this.userPromise = isPromise(this.opts.user)
? this.opts.user
@ -91,14 +89,14 @@
init: false,
user: user
});
stream.on('follow', this.onStreamFollow);
stream.on('unfollow', this.onStreamUnfollow);
this.stream.on('follow', this.onStreamFollow);
this.stream.on('unfollow', this.onStreamUnfollow);
});
});
this.on('unmount', () => {
stream.off('follow', this.onStreamFollow);
stream.off('unfollow', this.onStreamUnfollow);
this.stream.off('follow', this.onStreamFollow);
this.stream.off('unfollow', this.onStreamUnfollow);
});
this.onStreamFollow = user => {

View file

@ -246,8 +246,6 @@
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.files = [];
this.folders = [];
this.hierarchyFolders = [];
@ -279,10 +277,10 @@
});
});
stream.on('drive_file_created', this.onStreamDriveFileCreated);
stream.on('drive_file_updated', this.onStreamDriveFileUpdated);
stream.on('drive_folder_created', this.onStreamDriveFolderCreated);
stream.on('drive_folder_updated', this.onStreamDriveFolderUpdated);
this.stream.on('drive_file_created', this.onStreamDriveFileCreated);
this.stream.on('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.on('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.on('drive_folder_updated', this.onStreamDriveFolderUpdated);
// Riotのバグでnullを渡しても""になる
// https://github.com/riot/riot/issues/2080
@ -295,10 +293,10 @@
});
this.on('unmount', () => {
stream.off('drive_file_created', this.onStreamDriveFileCreated);
stream.off('drive_file_updated', this.onStreamDriveFileUpdated);
stream.off('drive_folder_created', this.onStreamDriveFolderCreated);
stream.off('drive_folder_updated', this.onStreamDriveFolderUpdated);
this.stream.off('drive_file_created', this.onStreamDriveFileCreated);
this.stream.off('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.off('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.off('drive_folder_updated', this.onStreamDriveFolderUpdated);
});
this.onStreamDriveFileCreated = file => {

View file

@ -73,8 +73,6 @@
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.user = null;
this.userPromise = isPromise(this.opts.user)
? this.opts.user
@ -88,14 +86,14 @@
init: false,
user: user
});
stream.on('follow', this.onStreamFollow);
stream.on('unfollow', this.onStreamUnfollow);
this.stream.on('follow', this.onStreamFollow);
this.stream.on('unfollow', this.onStreamUnfollow);
});
});
this.on('unmount', () => {
stream.off('follow', this.onStreamFollow);
stream.off('unfollow', this.onStreamUnfollow);
this.stream.off('follow', this.onStreamFollow);
this.stream.off('unfollow', this.onStreamUnfollow);
});
this.onStreamFollow = user => {

View file

@ -61,13 +61,11 @@
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.images = [];
this.initializing = true;
this.on('mount', () => {
stream.on('drive_file_created', this.onStreamDriveFileCreated);
this.stream.on('drive_file_created', this.onStreamDriveFileCreated);
this.api('drive/stream', {
type: 'image/*',
@ -81,7 +79,7 @@
});
this.on('unmount', () => {
stream.off('drive_file_created', this.onStreamDriveFileCreated);
this.stream.off('drive_file_created', this.onStreamDriveFileCreated);
});
this.onStreamDriveFileCreated = file => {

View file

@ -36,17 +36,15 @@
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.isLoading = true;
this.isEmpty = false;
this.moreLoading = false;
this.noFollowing = this.I.following_count == 0;
this.on('mount', () => {
stream.on('post', this.onStreamPost);
stream.on('follow', this.onStreamFollow);
stream.on('unfollow', this.onStreamUnfollow);
this.stream.on('post', this.onStreamPost);
this.stream.on('follow', this.onStreamFollow);
this.stream.on('unfollow', this.onStreamUnfollow);
document.addEventListener('keydown', this.onDocumentKeydown);
window.addEventListener('scroll', this.onScroll);
@ -55,9 +53,9 @@
});
this.on('unmount', () => {
stream.off('post', this.onStreamPost);
stream.off('follow', this.onStreamFollow);
stream.off('unfollow', this.onStreamUnfollow);
this.stream.off('post', this.onStreamPost);
this.stream.off('follow', this.onStreamFollow);
this.stream.off('unfollow', this.onStreamUnfollow);
document.removeEventListener('keydown', this.onDocumentKeydown);
window.removeEventListener('scroll', this.onScroll);

View file

@ -192,10 +192,8 @@
this.mixin('i');
this.mixin('api');
this.mixin('user-preview');
this.mixin('stream');
const stream = this.stream.event;
this.mixin('user-preview');
this.notifications = [];
this.loading = true;
@ -208,11 +206,11 @@
});
});
stream.on('notification', this.onNotification);
this.stream.on('notification', this.onNotification);
});
this.on('unmount', () => {
stream.off('notification', this.onNotification);
this.stream.off('notification', this.onNotification);
});
this.onNotification = notification => {

View file

@ -14,8 +14,6 @@
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.unreadCount = 0;
this.page = this.opts.mode || 'timeline';
@ -26,12 +24,12 @@
});
document.title = 'Misskey';
Progress.start();
stream.on('post', this.onStreamPost);
this.stream.on('post', this.onStreamPost);
document.addEventListener('visibilitychange', this.windowOnVisibilitychange, false);
});
this.on('unmount', () => {
stream.off('post', this.onStreamPost);
this.stream.off('post', this.onStreamPost);
document.removeEventListener('visibilitychange', this.windowOnVisibilitychange);
});

View file

@ -369,7 +369,7 @@
type: 'capture',
id: this.p.id
});
this.stream.event.on('post-updated', this.onStreamPostUpdated);
this.stream.on('post-updated', this.onStreamPostUpdated);
};
this.decapture = () => {
@ -377,7 +377,7 @@
type: 'decapture',
id: this.p.id
});
this.stream.event.off('post-updated', this.onStreamPostUpdated);
this.stream.off('post-updated', this.onStreamPostUpdated);
};
this.on('mount', () => {

View file

@ -99,13 +99,11 @@
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.page = this.opts.page;
this.on('mount', () => {
stream.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
stream.on('unread_messaging_message', this.onUnreadMessagingMessage);
this.stream.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.on('unread_messaging_message', this.onUnreadMessagingMessage);
// Fetch count of unread messaging messages
this.api('messaging/unread').then(res => {
@ -118,8 +116,8 @@
});
this.on('unmount', () => {
stream.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
stream.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.stream.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.off('unread_messaging_message', this.onUnreadMessagingMessage);
});
this.onReadAllMessagingMessages = () => {