summaryrefslogtreecommitdiffstats
path: root/web/react/stores
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/stores')
-rw-r--r--web/react/stores/browser_store.jsx80
-rw-r--r--web/react/stores/config_store.jsx65
-rw-r--r--web/react/stores/error_store.jsx81
-rw-r--r--web/react/stores/post_store.jsx387
-rw-r--r--web/react/stores/socket_store.jsx67
-rw-r--r--web/react/stores/team_store.jsx97
-rw-r--r--web/react/stores/user_store.jsx336
7 files changed, 633 insertions, 480 deletions
diff --git a/web/react/stores/browser_store.jsx b/web/react/stores/browser_store.jsx
index b1f51e5f4..e1ca52746 100644
--- a/web/react/stores/browser_store.jsx
+++ b/web/react/stores/browser_store.jsx
@@ -12,81 +12,70 @@ function getPrefix() {
// Also change model/utils.go ETAG_ROOT_VERSION
var BROWSER_STORE_VERSION = '.5';
-module.exports = {
- initialized: false,
+class BrowserStoreClass {
+ constructor() {
+ this.getItem = this.getItem.bind(this);
+ this.setItem = this.setItem.bind(this);
+ this.removeItem = this.removeItem.bind(this);
+ this.setGlobalItem = this.setGlobalItem.bind(this);
+ this.getGlobalItem = this.getGlobalItem.bind(this);
+ this.removeGlobalItem = this.removeGlobalItem.bind(this);
+ this.clear = this.clear.bind(this);
+ this.actionOnItemsWithPrefix = this.actionOnItemsWithPrefix.bind(this);
+ this.isLocalStorageSupported = this.isLocalStorageSupported.bind(this);
- initialize: function() {
var currentVersion = localStorage.getItem('local_storage_version');
if (currentVersion !== BROWSER_STORE_VERSION) {
this.clear();
localStorage.setItem('local_storage_version', BROWSER_STORE_VERSION);
}
- this.initialized = true;
- },
+ }
- getItem: function(name, defaultValue) {
+ getItem(name, defaultValue) {
return this.getGlobalItem(getPrefix() + name, defaultValue);
- },
+ }
- setItem: function(name, value) {
+ setItem(name, value) {
this.setGlobalItem(getPrefix() + name, value);
- },
-
- removeItem: function(name) {
- if (!this.initialized) {
- this.initialize();
- }
+ }
+ removeItem(name) {
localStorage.removeItem(getPrefix() + name);
- },
-
- setGlobalItem: function(name, value) {
- if (!this.initialized) {
- this.initialize();
- }
+ }
+ setGlobalItem(name, value) {
localStorage.setItem(name, JSON.stringify(value));
- },
-
- getGlobalItem: function(name, defaultValue) {
- if (!this.initialized) {
- this.initialize();
- }
+ }
+ getGlobalItem(name, defaultValue) {
var result = null;
try {
result = JSON.parse(localStorage.getItem(name));
- } catch (err) {}
+ } catch (err) {
+ result = null;
+ }
if (result === null && typeof defaultValue !== 'undefined') {
result = defaultValue;
}
return result;
- },
-
- removeGlobalItem: function(name) {
- if (!this.initialized) {
- this.initialize();
- }
+ }
+ removeGlobalItem(name) {
localStorage.removeItem(name);
- },
+ }
- clear: function() {
+ clear() {
localStorage.clear();
sessionStorage.clear();
- },
+ }
/**
* Preforms the given action on each item that has the given prefix
* Signature for action is action(key, value)
*/
- actionOnItemsWithPrefix: function(prefix, action) {
- if (!this.initialized) {
- this.initialize();
- }
-
+ actionOnItemsWithPrefix(prefix, action) {
var globalPrefix = getPrefix();
var globalPrefixiLen = globalPrefix.length;
for (var key in localStorage) {
@@ -95,9 +84,9 @@ module.exports = {
action(userkey, this.getGlobalItem(key));
}
}
- },
+ }
- isLocalStorageSupported: function() {
+ isLocalStorageSupported() {
try {
sessionStorage.setItem('testSession', '1');
sessionStorage.removeItem('testSession');
@@ -113,4 +102,7 @@ module.exports = {
return false;
}
}
-};
+}
+
+var BrowserStore = new BrowserStoreClass();
+export default BrowserStore;
diff --git a/web/react/stores/config_store.jsx b/web/react/stores/config_store.jsx
index 7ff177b35..b397937be 100644
--- a/web/react/stores/config_store.jsx
+++ b/web/react/stores/config_store.jsx
@@ -3,7 +3,6 @@
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var EventEmitter = require('events').EventEmitter;
-var assign = require('object-assign');
var BrowserStore = require('../stores/browser_store.jsx');
@@ -12,45 +11,59 @@ var ActionTypes = Constants.ActionTypes;
var CHANGE_EVENT = 'change';
-var ConfigStore = assign({}, EventEmitter.prototype, {
- emitChange: function emitChange() {
+class ConfigStoreClass extends EventEmitter {
+ constructor() {
+ super();
+
+ this.emitChange = this.emitChange.bind(this);
+ this.addChangeListener = this.addChangeListener.bind(this);
+ this.removeChangeListener = this.removeChangeListener.bind(this);
+ this.getSetting = this.getSetting.bind(this);
+ this.getSettingAsBoolean = this.getSettingAsBoolean.bind(this);
+ this.updateStoredSettings = this.updateStoredSettings.bind(this);
+ }
+ emitChange() {
this.emit(CHANGE_EVENT);
- },
- addChangeListener: function addChangeListener(callback) {
+ }
+ addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function removeChangeListener(callback) {
+ }
+ removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
- },
- getSetting: function getSetting(key, defaultValue) {
+ }
+ getSetting(key, defaultValue) {
return BrowserStore.getItem('config_' + key, defaultValue);
- },
- getSettingAsBoolean: function getSettingAsNumber(key, defaultValue) {
- var value = ConfigStore.getSetting(key, defaultValue);
+ }
+ getSettingAsBoolean(key, defaultValue) {
+ var value = this.getSetting(key, defaultValue);
if (typeof value !== 'string') {
- return !!value;
- } else {
- return value === 'true';
+ return Boolean(value);
}
- },
- updateStoredSettings: function updateStoredSettings(settings) {
- for (var key in settings) {
- BrowserStore.setItem('config_' + key, settings[key]);
+
+ return value === 'true';
+ }
+ updateStoredSettings(settings) {
+ for (let key in settings) {
+ if (settings.hasOwnProperty(key)) {
+ BrowserStore.setItem('config_' + key, settings[key]);
+ }
}
}
-});
+}
+
+var ConfigStore = new ConfigStoreClass();
ConfigStore.dispatchToken = AppDispatcher.register(function registry(payload) {
var action = payload.action;
switch (action.type) {
- case ActionTypes.RECIEVED_CONFIG:
- ConfigStore.updateStoredSettings(action.settings);
- ConfigStore.emitChange();
- break;
- default:
+ case ActionTypes.RECIEVED_CONFIG:
+ ConfigStore.updateStoredSettings(action.settings);
+ ConfigStore.emitChange();
+ break;
+ default:
}
});
-module.exports = ConfigStore;
+export default ConfigStore;
diff --git a/web/react/stores/error_store.jsx b/web/react/stores/error_store.jsx
index 203b692ec..597c88cff 100644
--- a/web/react/stores/error_store.jsx
+++ b/web/react/stores/error_store.jsx
@@ -3,7 +3,6 @@
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var EventEmitter = require('events').EventEmitter;
-var assign = require('object-assign');
var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
@@ -12,43 +11,53 @@ var BrowserStore = require('../stores/browser_store.jsx');
var CHANGE_EVENT = 'change';
-var ErrorStore = assign({}, EventEmitter.prototype, {
-
- emitChange: function() {
- this.emit(CHANGE_EVENT);
- },
-
- addChangeListener: function(callback) {
- this.on(CHANGE_EVENT, callback);
- },
-
- removeChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT, callback);
- },
- handledError: function() {
- BrowserStore.removeItem("last_error");
- },
- getLastError: function() {
- return BrowserStore.getItem('last_error');
- },
-
- _storeLastError: function(error) {
- BrowserStore.setItem("last_error", error);
- },
-});
-
-ErrorStore.dispatchToken = AppDispatcher.register(function(payload) {
- var action = payload.action;
- switch(action.type) {
+class ErrorStoreClass extends EventEmitter {
+ constructor() {
+ super();
+
+ this.emitChange = this.emitChange.bind(this);
+ this.addChangeListener = this.addChangeListener.bind(this);
+ this.removeChangeListener = this.removeChangeListener.bind(this);
+ this.handledError = this.handledError.bind(this);
+ this.getLastError = this.getLastError.bind(this);
+ this.storeLastError = this.storeLastError.bind(this);
+ }
+
+ emitChange() {
+ this.emit(CHANGE_EVENT);
+ }
+
+ addChangeListener(callback) {
+ this.on(CHANGE_EVENT, callback);
+ }
+
+ removeChangeListener(callback) {
+ this.removeListener(CHANGE_EVENT, callback);
+ }
+ handledError() {
+ BrowserStore.removeItem('last_error');
+ }
+ getLastError() {
+ return BrowserStore.getItem('last_error');
+ }
+
+ storeLastError(error) {
+ BrowserStore.setItem('last_error', error);
+ }
+}
+
+var ErrorStore = new ErrorStoreClass();
+
+ErrorStore.dispatchToken = AppDispatcher.register(function registry(payload) {
+ var action = payload.action;
+ switch (action.type) {
case ActionTypes.RECIEVED_ERROR:
- ErrorStore._storeLastError(action.err);
- ErrorStore.emitChange();
- break;
+ ErrorStore.storeLastError(action.err);
+ ErrorStore.emitChange();
+ break;
default:
- }
+ }
});
-module.exports = ErrorStore;
-
-
+export default ErrorStore;
diff --git a/web/react/stores/post_store.jsx b/web/react/stores/post_store.jsx
index 4038814d2..5ffe65021 100644
--- a/web/react/stores/post_store.jsx
+++ b/web/react/stores/post_store.jsx
@@ -3,7 +3,6 @@
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var EventEmitter = require('events').EventEmitter;
-var assign = require('object-assign');
var ChannelStore = require('../stores/channel_store.jsx');
var BrowserStore = require('../stores/browser_store.jsx');
@@ -18,109 +17,169 @@ var SELECTED_POST_CHANGE_EVENT = 'selected_post_change';
var MENTION_DATA_CHANGE_EVENT = 'mention_data_change';
var ADD_MENTION_EVENT = 'add_mention';
-var PostStore = assign({}, EventEmitter.prototype, {
- emitChange: function emitChange() {
+class PostStoreClass extends EventEmitter {
+ constructor() {
+ super();
+
+ this.emitChange = this.emitChange.bind(this);
+ this.addChangeListener = this.addChangeListener.bind(this);
+ this.removeChangeListener = this.removeChangeListener.bind(this);
+ this.emitSearchChange = this.emitSearchChange.bind(this);
+ this.addSearchChangeListener = this.addSearchChangeListener.bind(this);
+ this.removeSearchChangeListener = this.removeSearchChangeListener.bind(this);
+ this.emitSearchTermChange = this.emitSearchTermChange.bind(this);
+ this.addSearchTermChangeListener = this.addSearchTermChangeListener.bind(this);
+ this.removeSearchTermChangeListener = this.removeSearchTermChangeListener.bind(this);
+ this.emitSelectedPostChange = this.emitSelectedPostChange.bind(this);
+ this.addSelectedPostChangeListener = this.addSelectedPostChangeListener.bind(this);
+ this.removeSelectedPostChangeListener = this.removeSelectedPostChangeListener.bind(this);
+ this.emitMentionDataChange = this.emitMentionDataChange.bind(this);
+ this.addMentionDataChangeListener = this.addMentionDataChangeListener.bind(this);
+ this.removeMentionDataChangeListener = this.removeMentionDataChangeListener.bind(this);
+ this.emitAddMention = this.emitAddMention.bind(this);
+ this.addAddMentionListener = this.addAddMentionListener.bind(this);
+ this.removeAddMentionListener = this.removeAddMentionListener.bind(this);
+ this.getCurrentPosts = this.getCurrentPosts.bind(this);
+ this.storePosts = this.storePosts.bind(this);
+ this.pStorePosts = this.pStorePosts.bind(this);
+ this.getPosts = this.getPosts.bind(this);
+ this.storePost = this.storePost.bind(this);
+ this.pStorePost = this.pStorePost.bind(this);
+ this.removePost = this.removePost.bind(this);
+ this.storePendingPost = this.storePendingPost.bind(this);
+ this.pStorePendingPosts = this.pStorePendingPosts.bind(this);
+ this.getPendingPosts = this.getPendingPosts.bind(this);
+ this.storeUnseenDeletedPost = this.storeUnseenDeletedPost.bind(this);
+ this.storeUnseenDeletedPosts = this.storeUnseenDeletedPosts.bind(this);
+ this.getUnseenDeletedPosts = this.getUnseenDeletedPosts.bind(this);
+ this.clearUnseenDeletedPosts = this.clearUnseenDeletedPosts.bind(this);
+ this.removePendingPost = this.removePendingPost.bind(this);
+ this.pRemovePendingPost = this.pRemovePendingPost.bind(this);
+ this.clearPendingPosts = this.clearPendingPosts.bind(this);
+ this.updatePendingPost = this.updatePendingPost.bind(this);
+ this.storeSearchResults = this.storeSearchResults.bind(this);
+ this.getSearchResults = this.getSearchResults.bind(this);
+ this.getIsMentionSearch = this.getIsMentionSearch.bind(this);
+ this.storeSelectedPost = this.storeSelectedPost.bind(this);
+ this.getSelectedPost = this.getSelectedPost.bind(this);
+ this.storeSearchTerm = this.storeSearchTerm.bind(this);
+ this.getSearchTerm = this.getSearchTerm.bind(this);
+ this.getEmptyDraft = this.getEmptyDraft.bind(this);
+ this.storeCurrentDraft = this.storeCurrentDraft.bind(this);
+ this.getCurrentDraft = this.getCurrentDraft.bind(this);
+ this.storeDraft = this.storeDraft.bind(this);
+ this.getDraft = this.getDraft.bind(this);
+ this.storeCommentDraft = this.storeCommentDraft.bind(this);
+ this.getCommentDraft = this.getCommentDraft.bind(this);
+ this.clearDraftUploads = this.clearDraftUploads.bind(this);
+ this.clearCommentDraftUploads = this.clearCommentDraftUploads.bind(this);
+ this.storeLatestUpdate = this.storeLatestUpdate.bind(this);
+ this.getLatestUpdate = this.getLatestUpdate.bind(this);
+ }
+ emitChange() {
this.emit(CHANGE_EVENT);
- },
+ }
- addChangeListener: function addChangeListener(callback) {
+ addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
- },
+ }
- removeChangeListener: function removeChangeListener(callback) {
+ removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
- },
+ }
- emitSearchChange: function emitSearchChange() {
+ emitSearchChange() {
this.emit(SEARCH_CHANGE_EVENT);
- },
+ }
- addSearchChangeListener: function addSearchChangeListener(callback) {
+ addSearchChangeListener(callback) {
this.on(SEARCH_CHANGE_EVENT, callback);
- },
+ }
- removeSearchChangeListener: function removeSearchChangeListener(callback) {
+ removeSearchChangeListener(callback) {
this.removeListener(SEARCH_CHANGE_EVENT, callback);
- },
+ }
- emitSearchTermChange: function emitSearchTermChange(doSearch, isMentionSearch) {
+ emitSearchTermChange(doSearch, isMentionSearch) {
this.emit(SEARCH_TERM_CHANGE_EVENT, doSearch, isMentionSearch);
- },
+ }
- addSearchTermChangeListener: function addSearchTermChangeListener(callback) {
+ addSearchTermChangeListener(callback) {
this.on(SEARCH_TERM_CHANGE_EVENT, callback);
- },
+ }
- removeSearchTermChangeListener: function removeSearchTermChangeListener(callback) {
+ removeSearchTermChangeListener(callback) {
this.removeListener(SEARCH_TERM_CHANGE_EVENT, callback);
- },
+ }
- emitSelectedPostChange: function emitSelectedPostChange(fromSearch) {
+ emitSelectedPostChange(fromSearch) {
this.emit(SELECTED_POST_CHANGE_EVENT, fromSearch);
- },
+ }
- addSelectedPostChangeListener: function addSelectedPostChangeListener(callback) {
+ addSelectedPostChangeListener(callback) {
this.on(SELECTED_POST_CHANGE_EVENT, callback);
- },
+ }
- removeSelectedPostChangeListener: function removeSelectedPostChangeListener(callback) {
+ removeSelectedPostChangeListener(callback) {
this.removeListener(SELECTED_POST_CHANGE_EVENT, callback);
- },
+ }
- emitMentionDataChange: function emitMentionDataChange(id, mentionText) {
+ emitMentionDataChange(id, mentionText) {
this.emit(MENTION_DATA_CHANGE_EVENT, id, mentionText);
- },
+ }
- addMentionDataChangeListener: function addMentionDataChangeListener(callback) {
+ addMentionDataChangeListener(callback) {
this.on(MENTION_DATA_CHANGE_EVENT, callback);
- },
+ }
- removeMentionDataChangeListener: function removeMentionDataChangeListener(callback) {
+ removeMentionDataChangeListener(callback) {
this.removeListener(MENTION_DATA_CHANGE_EVENT, callback);
- },
+ }
- emitAddMention: function emitAddMention(id, username) {
+ emitAddMention(id, username) {
this.emit(ADD_MENTION_EVENT, id, username);
- },
+ }
- addAddMentionListener: function addAddMentionListener(callback) {
+ addAddMentionListener(callback) {
this.on(ADD_MENTION_EVENT, callback);
- },
+ }
- removeAddMentionListener: function removeAddMentionListener(callback) {
+ removeAddMentionListener(callback) {
this.removeListener(ADD_MENTION_EVENT, callback);
- },
+ }
- getCurrentPosts: function getCurrentPosts() {
+ getCurrentPosts() {
var currentId = ChannelStore.getCurrentId();
if (currentId != null) {
return this.getPosts(currentId);
}
return null;
- },
- storePosts: function storePosts(channelId, newPostList) {
+ }
+ storePosts(channelId, newPostList) {
if (isPostListNull(newPostList)) {
return;
}
- var postList = makePostListNonNull(PostStore.getPosts(channelId));
-
- for (var pid in newPostList.posts) {
- var np = newPostList.posts[pid];
- if (np.delete_at === 0) {
- postList.posts[pid] = np;
- if (postList.order.indexOf(pid) === -1) {
- postList.order.push(pid);
- }
- } else {
- if (pid in postList.posts) {
- delete postList.posts[pid];
- }
-
- var index = postList.order.indexOf(pid);
- if (index !== -1) {
- postList.order.splice(index, 1);
+ var postList = makePostListNonNull(this.getPosts(channelId));
+
+ for (let pid in newPostList.posts) {
+ if (newPostList.posts.hasOwnProperty(pid)) {
+ var np = newPostList.posts[pid];
+ if (np.delete_at === 0) {
+ postList.posts[pid] = np;
+ if (postList.order.indexOf(pid) === -1) {
+ postList.order.push(pid);
+ }
+ } else {
+ if (pid in postList.posts) {
+ delete postList.posts[pid];
+ }
+
+ var index = postList.order.indexOf(pid);
+ if (index !== -1) {
+ postList.order.splice(index, 1);
+ }
}
}
}
@@ -146,19 +205,19 @@ var PostStore = assign({}, EventEmitter.prototype, {
this.storeLatestUpdate(channelId, latestUpdate);
this.pStorePosts(channelId, postList);
this.emitChange();
- },
- pStorePosts: function pStorePosts(channelId, posts) {
+ }
+ pStorePosts(channelId, posts) {
BrowserStore.setItem('posts_' + channelId, posts);
- },
- getPosts: function getPosts(channelId) {
+ }
+ getPosts(channelId) {
return BrowserStore.getItem('posts_' + channelId);
- },
- storePost: function(post) {
+ }
+ storePost(post) {
this.pStorePost(post);
this.emitChange();
- },
- pStorePost: function(post) {
- var postList = PostStore.getPosts(post.channel_id);
+ }
+ pStorePost(post) {
+ var postList = this.getPosts(post.channel_id);
postList = makePostListNonNull(postList);
if (post.pending_post_id !== '') {
@@ -173,9 +232,9 @@ var PostStore = assign({}, EventEmitter.prototype, {
}
this.pStorePosts(post.channel_id, postList);
- },
- removePost: function(postId, channelId) {
- var postList = PostStore.getPosts(channelId);
+ }
+ removePost(postId, channelId) {
+ var postList = this.getPosts(channelId);
if (isPostListNull(postList)) {
return;
}
@@ -190,8 +249,8 @@ var PostStore = assign({}, EventEmitter.prototype, {
}
this.pStorePosts(channelId, postList);
- },
- storePendingPost: function(post) {
+ }
+ storePendingPost(post) {
post.state = Constants.POST_LOADING;
var postList = this.getPendingPosts(post.channel_id);
@@ -199,10 +258,10 @@ var PostStore = assign({}, EventEmitter.prototype, {
postList.posts[post.pending_post_id] = post;
postList.order.unshift(post.pending_post_id);
- this._storePendingPosts(post.channel_id, postList);
+ this.pStorePendingPosts(post.channel_id, postList);
this.emitChange();
- },
- _storePendingPosts: function(channelId, postList) {
+ }
+ pStorePendingPosts(channelId, postList) {
var posts = postList.posts;
// sort failed posts to the bottom
@@ -225,11 +284,11 @@ var PostStore = assign({}, EventEmitter.prototype, {
});
BrowserStore.setItem('pending_posts_' + channelId, postList);
- },
- getPendingPosts: function(channelId) {
+ }
+ getPendingPosts(channelId) {
return BrowserStore.getItem('pending_posts_' + channelId);
- },
- storeUnseenDeletedPost: function(post) {
+ }
+ storeUnseenDeletedPost(post) {
var posts = this.getUnseenDeletedPosts(post.channel_id);
if (!posts) {
@@ -241,21 +300,21 @@ var PostStore = assign({}, EventEmitter.prototype, {
posts[post.id] = post;
this.storeUnseenDeletedPosts(post.channel_id, posts);
- },
- storeUnseenDeletedPosts: function(channelId, posts) {
+ }
+ storeUnseenDeletedPosts(channelId, posts) {
BrowserStore.setItem('deleted_posts_' + channelId, posts);
- },
- getUnseenDeletedPosts: function(channelId) {
+ }
+ getUnseenDeletedPosts(channelId) {
return BrowserStore.getItem('deleted_posts_' + channelId);
- },
- clearUnseenDeletedPosts: function(channelId) {
+ }
+ clearUnseenDeletedPosts(channelId) {
BrowserStore.setItem('deleted_posts_' + channelId, {});
- },
- removePendingPost: function(channelId, pendingPostId) {
- this._removePendingPost(channelId, pendingPostId);
+ }
+ removePendingPost(channelId, pendingPostId) {
+ this.pRemovePendingPost(channelId, pendingPostId);
this.emitChange();
- },
- _removePendingPost: function(channelId, pendingPostId) {
+ }
+ pRemovePendingPost(channelId, pendingPostId) {
var postList = this.getPendingPosts(channelId);
postList = makePostListNonNull(postList);
@@ -267,14 +326,14 @@ var PostStore = assign({}, EventEmitter.prototype, {
postList.order.splice(index, 1);
}
- this._storePendingPosts(channelId, postList);
- },
- clearPendingPosts: function() {
+ this.pStorePendingPosts(channelId, postList);
+ }
+ clearPendingPosts() {
BrowserStore.actionOnItemsWithPrefix('pending_posts_', function clearPending(key) {
BrowserStore.removeItem(key);
});
- },
- updatePendingPost: function(post) {
+ }
+ updatePendingPost(post) {
var postList = this.getPendingPosts(post.channel_id);
postList = makePostListNonNull(postList);
@@ -283,112 +342,114 @@ var PostStore = assign({}, EventEmitter.prototype, {
}
postList.posts[post.pending_post_id] = post;
- this._storePendingPosts(post.channel_id, postList);
+ this.pStorePendingPosts(post.channel_id, postList);
this.emitChange();
- },
- storeSearchResults: function storeSearchResults(results, isMentionSearch) {
+ }
+ storeSearchResults(results, isMentionSearch) {
BrowserStore.setItem('search_results', results);
BrowserStore.setItem('is_mention_search', Boolean(isMentionSearch));
- },
- getSearchResults: function getSearchResults() {
+ }
+ getSearchResults() {
return BrowserStore.getItem('search_results');
- },
- getIsMentionSearch: function getIsMentionSearch() {
+ }
+ getIsMentionSearch() {
return BrowserStore.getItem('is_mention_search');
- },
- storeSelectedPost: function storeSelectedPost(postList) {
+ }
+ storeSelectedPost(postList) {
BrowserStore.setItem('select_post', postList);
- },
- getSelectedPost: function getSelectedPost() {
+ }
+ getSelectedPost() {
return BrowserStore.getItem('select_post');
- },
- storeSearchTerm: function storeSearchTerm(term) {
+ }
+ storeSearchTerm(term) {
BrowserStore.setItem('search_term', term);
- },
- getSearchTerm: function getSearchTerm() {
+ }
+ getSearchTerm() {
return BrowserStore.getItem('search_term');
- },
- getEmptyDraft: function getEmptyDraft(draft) {
+ }
+ getEmptyDraft() {
return {message: '', uploadsInProgress: [], previews: []};
- },
- storeCurrentDraft: function storeCurrentDraft(draft) {
+ }
+ storeCurrentDraft(draft) {
var channelId = ChannelStore.getCurrentId();
BrowserStore.setItem('draft_' + channelId, draft);
- },
- getCurrentDraft: function getCurrentDraft() {
+ }
+ getCurrentDraft() {
var channelId = ChannelStore.getCurrentId();
- return PostStore.getDraft(channelId);
- },
- storeDraft: function storeDraft(channelId, draft) {
+ return this.getDraft(channelId);
+ }
+ storeDraft(channelId, draft) {
BrowserStore.setItem('draft_' + channelId, draft);
- },
- getDraft: function getDraft(channelId) {
- return BrowserStore.getItem('draft_' + channelId, PostStore.getEmptyDraft());
- },
- storeCommentDraft: function storeCommentDraft(parentPostId, draft) {
+ }
+ getDraft(channelId) {
+ return BrowserStore.getItem('draft_' + channelId, this.getEmptyDraft());
+ }
+ storeCommentDraft(parentPostId, draft) {
BrowserStore.setItem('comment_draft_' + parentPostId, draft);
- },
- getCommentDraft: function getCommentDraft(parentPostId) {
- return BrowserStore.getItem('comment_draft_' + parentPostId, PostStore.getEmptyDraft());
- },
- clearDraftUploads: function clearDraftUploads() {
+ }
+ getCommentDraft(parentPostId) {
+ return BrowserStore.getItem('comment_draft_' + parentPostId, this.getEmptyDraft());
+ }
+ clearDraftUploads() {
BrowserStore.actionOnItemsWithPrefix('draft_', function clearUploads(key, value) {
if (value) {
value.uploadsInProgress = [];
BrowserStore.setItem(key, value);
}
});
- },
- clearCommentDraftUploads: function clearCommentDraftUploads() {
+ }
+ clearCommentDraftUploads() {
BrowserStore.actionOnItemsWithPrefix('comment_draft_', function clearUploads(key, value) {
if (value) {
value.uploadsInProgress = [];
BrowserStore.setItem(key, value);
}
});
- },
- storeLatestUpdate: function(channelId, time) {
+ }
+ storeLatestUpdate(channelId, time) {
BrowserStore.setItem('latest_post_' + channelId, time);
- },
- getLatestUpdate: function(channelId) {
+ }
+ getLatestUpdate(channelId) {
return BrowserStore.getItem('latest_post_' + channelId, 0);
}
-});
+}
+
+var PostStore = new PostStoreClass();
PostStore.dispatchToken = AppDispatcher.register(function registry(payload) {
var action = payload.action;
switch (action.type) {
- case ActionTypes.RECIEVED_POSTS:
- PostStore.storePosts(action.id, makePostListNonNull(action.post_list));
- break;
- case ActionTypes.RECIEVED_POST:
- PostStore.pStorePost(action.post);
- PostStore.emitChange();
- break;
- case ActionTypes.RECIEVED_SEARCH:
- PostStore.storeSearchResults(action.results, action.is_mention_search);
- PostStore.emitSearchChange();
- break;
- case ActionTypes.RECIEVED_SEARCH_TERM:
- PostStore.storeSearchTerm(action.term);
- PostStore.emitSearchTermChange(action.do_search, action.is_mention_search);
- break;
- case ActionTypes.RECIEVED_POST_SELECTED:
- PostStore.storeSelectedPost(action.post_list);
- PostStore.emitSelectedPostChange(action.from_search);
- break;
- case ActionTypes.RECIEVED_MENTION_DATA:
- PostStore.emitMentionDataChange(action.id, action.mention_text);
- break;
- case ActionTypes.RECIEVED_ADD_MENTION:
- PostStore.emitAddMention(action.id, action.username);
- break;
- default:
+ case ActionTypes.RECIEVED_POSTS:
+ PostStore.storePosts(action.id, makePostListNonNull(action.post_list));
+ break;
+ case ActionTypes.RECIEVED_POST:
+ PostStore.pStorePost(action.post);
+ PostStore.emitChange();
+ break;
+ case ActionTypes.RECIEVED_SEARCH:
+ PostStore.storeSearchResults(action.results, action.is_mention_search);
+ PostStore.emitSearchChange();
+ break;
+ case ActionTypes.RECIEVED_SEARCH_TERM:
+ PostStore.storeSearchTerm(action.term);
+ PostStore.emitSearchTermChange(action.do_search, action.is_mention_search);
+ break;
+ case ActionTypes.RECIEVED_POST_SELECTED:
+ PostStore.storeSelectedPost(action.post_list);
+ PostStore.emitSelectedPostChange(action.from_search);
+ break;
+ case ActionTypes.RECIEVED_MENTION_DATA:
+ PostStore.emitMentionDataChange(action.id, action.mention_text);
+ break;
+ case ActionTypes.RECIEVED_ADD_MENTION:
+ PostStore.emitAddMention(action.id, action.username);
+ break;
+ default:
}
});
-module.exports = PostStore;
+export default PostStore;
function makePostListNonNull(pl) {
var postList = pl;
diff --git a/web/react/stores/socket_store.jsx b/web/react/stores/socket_store.jsx
index e43a8f2be..ae74059d1 100644
--- a/web/react/stores/socket_store.jsx
+++ b/web/react/stores/socket_store.jsx
@@ -2,10 +2,8 @@
// See License.txt for license information.
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
-var UserStore = require('./user_store.jsx')
+var UserStore = require('./user_store.jsx');
var EventEmitter = require('events').EventEmitter;
-var assign = require('object-assign');
-var client = require('../utils/client.jsx');
var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
@@ -14,14 +12,24 @@ var CHANGE_EVENT = 'change';
var conn;
-var SocketStore = assign({}, EventEmitter.prototype, {
- initialize: function() {
+class SocketStoreClass extends EventEmitter {
+ constructor() {
+ super();
+
+ this.initialize = this.initialize.bind(this);
+ this.emitChange = this.emitChange.bind(this);
+ this.addChangeListener = this.addChangeListener.bind(this);
+ this.removeChangeListener = this.removeChangeListener.bind(this);
+ this.sendMessage = this.sendMessage.bind(this);
+
+ this.initialize();
+ }
+ initialize() {
if (!UserStore.getCurrentId()) {
return;
}
- var self = this;
- self.setMaxListeners(0);
+ this.setMaxListeners(0);
if (window.WebSocket && !conn) {
var protocol = 'ws://';
@@ -29,24 +37,24 @@ var SocketStore = assign({}, EventEmitter.prototype, {
protocol = 'wss://';
}
var connUrl = protocol + location.host + '/api/v1/websocket';
- console.log('connecting to ' + connUrl);
+ console.log('connecting to ' + connUrl); //eslint-disable-line no-console
conn = new WebSocket(connUrl);
conn.onclose = function closeConn(evt) {
- console.log('websocket closed');
- console.log(evt);
+ console.log('websocket closed'); //eslint-disable-line no-console
+ console.log(evt); //eslint-disable-line no-console
conn = null;
setTimeout(
function reconnect() {
- self.initialize();
- },
+ this.initialize();
+ }.bind(this),
3000
);
- };
+ }.bind(this);
conn.onerror = function connError(evt) {
- console.log('websocket error');
- console.log(evt);
+ console.log('websocket error'); //eslint-disable-line no-console
+ console.log(evt); //eslint-disable-line no-console
};
conn.onmessage = function connMessage(evt) {
@@ -56,17 +64,17 @@ var SocketStore = assign({}, EventEmitter.prototype, {
});
};
}
- },
- emitChange: function(msg) {
+ }
+ emitChange(msg) {
this.emit(CHANGE_EVENT, msg);
- },
- addChangeListener: function(callback) {
+ }
+ addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function(callback) {
+ }
+ removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
- },
- sendMessage: function(msg) {
+ }
+ sendMessage(msg) {
if (conn && conn.readyState === WebSocket.OPEN) {
conn.send(JSON.stringify(msg));
} else if (!conn || conn.readyState === WebSocket.Closed) {
@@ -74,19 +82,20 @@ var SocketStore = assign({}, EventEmitter.prototype, {
this.initialize();
}
}
-});
+}
+
+var SocketStore = new SocketStoreClass();
-SocketStore.dispatchToken = AppDispatcher.register(function(payload) {
+SocketStore.dispatchToken = AppDispatcher.register(function registry(payload) {
var action = payload.action;
switch (action.type) {
- case ActionTypes.RECIEVED_MSG:
+ case ActionTypes.RECIEVED_MSG:
SocketStore.emitChange(action.msg);
break;
- default:
+ default:
}
});
-SocketStore.initialize();
-module.exports = SocketStore;
+export default SocketStore;
diff --git a/web/react/stores/team_store.jsx b/web/react/stores/team_store.jsx
index 3f2248c44..1f33fe03b 100644
--- a/web/react/stores/team_store.jsx
+++ b/web/react/stores/team_store.jsx
@@ -3,7 +3,6 @@
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var EventEmitter = require('events').EventEmitter;
-var assign = require('object-assign');
var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
@@ -19,21 +18,38 @@ function getWindowLocationOrigin() {
return utils.getWindowLocationOrigin();
}
-var TeamStore = assign({}, EventEmitter.prototype, {
- emitChange: function() {
+class TeamStoreClass extends EventEmitter {
+ constructor() {
+ super();
+
+ this.emitChange = this.emitChange.bind(this);
+ this.addChangeListener = this.addChangeListener.bind(this);
+ this.removeChangeListener = this.removeChangeListener.bind(this);
+ this.get = this.get.bind(this);
+ this.getByName = this.getByName.bind(this);
+ this.getAll = this.getAll.bind(this);
+ this.setCurrentId = this.setCurrentId.bind(this);
+ this.getCurrentId = this.getCurrentId.bind(this);
+ this.getCurrent = this.getCurrent.bind(this);
+ this.getCurrentTeamUrl = this.getCurrentTeamUrl.bind(this);
+ this.storeTeam = this.storeTeam.bind(this);
+ this.pStoreTeams = this.pStoreTeams.bind(this);
+ this.pGetTeams = this.pGetTeams.bind(this);
+ }
+ emitChange() {
this.emit(CHANGE_EVENT);
- },
- addChangeListener: function(callback) {
+ }
+ addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function(callback) {
+ }
+ removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
- },
- get: function(id) {
+ }
+ get(id) {
var c = this.pGetTeams();
return c[id];
- },
- getByName: function(name) {
+ }
+ getByName(name) {
var t = this.pGetTeams();
for (var id in t) {
@@ -43,64 +59,65 @@ var TeamStore = assign({}, EventEmitter.prototype, {
}
return null;
- },
- getAll: function() {
+ }
+ getAll() {
return this.pGetTeams();
- },
- setCurrentId: function(id) {
+ }
+ setCurrentId(id) {
if (id === null) {
BrowserStore.removeItem('current_team_id');
} else {
BrowserStore.setItem('current_team_id', id);
}
- },
- getCurrentId: function() {
+ }
+ getCurrentId() {
return BrowserStore.getItem('current_team_id');
- },
- getCurrent: function() {
- var currentId = TeamStore.getCurrentId();
+ }
+ getCurrent() {
+ var currentId = this.getCurrentId();
if (currentId !== null) {
return this.get(currentId);
}
return null;
- },
- getCurrentTeamUrl: function() {
+ }
+ getCurrentTeamUrl() {
if (this.getCurrent()) {
return getWindowLocationOrigin() + '/' + this.getCurrent().name;
}
return null;
- },
- storeTeam: function(team) {
+ }
+ storeTeam(team) {
var teams = this.pGetTeams();
teams[team.id] = team;
this.pStoreTeams(teams);
- },
- pStoreTeams: function(teams) {
+ }
+ pStoreTeams(teams) {
BrowserStore.setItem('user_teams', teams);
- },
- pGetTeams: function() {
+ }
+ pGetTeams() {
return BrowserStore.getItem('user_teams', {});
}
-});
+}
+
+var TeamStore = new TeamStoreClass();
TeamStore.dispatchToken = AppDispatcher.register(function registry(payload) {
var action = payload.action;
switch (action.type) {
+ case ActionTypes.CLICK_TEAM:
+ TeamStore.setCurrentId(action.id);
+ TeamStore.emitChange();
+ break;
- case ActionTypes.CLICK_TEAM:
- TeamStore.setCurrentId(action.id);
- TeamStore.emitChange();
- break;
-
- case ActionTypes.RECIEVED_TEAM:
- TeamStore.storeTeam(action.team);
- TeamStore.emitChange();
- break;
+ case ActionTypes.RECIEVED_TEAM:
+ TeamStore.storeTeam(action.team);
+ TeamStore.emitChange();
+ break;
- default:
+ default:
}
});
-module.exports = TeamStore;
+export default TeamStore;
diff --git a/web/react/stores/user_store.jsx b/web/react/stores/user_store.jsx
index 248495dac..f75c1d4c3 100644
--- a/web/react/stores/user_store.jsx
+++ b/web/react/stores/user_store.jsx
@@ -3,7 +3,6 @@
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var EventEmitter = require('events').EventEmitter;
-var assign = require('object-assign');
var client = require('../utils/client.jsx');
var Constants = require('../utils/constants.jsx');
@@ -16,64 +15,114 @@ var CHANGE_EVENT_AUDITS = 'change_audits';
var CHANGE_EVENT_TEAMS = 'change_teams';
var CHANGE_EVENT_STATUSES = 'change_statuses';
-var UserStore = assign({}, EventEmitter.prototype, {
+class UserStoreClass extends EventEmitter {
+ constructor() {
+ super();
- gCurrentId: null,
+ this.emitChange = this.emitChange.bind(this);
+ this.addChangeListener = this.addChangeListener.bind(this);
+ this.removeChangeListener = this.removeChangeListener.bind(this);
+ this.emitSessionsChange = this.emitSessionsChange.bind(this);
+ this.addSessionsChangeListener = this.addSessionsChangeListener.bind(this);
+ this.removeSessionsChangeListener = this.removeSessionsChangeListener.bind(this);
+ this.emitAuditsChange = this.emitAuditsChange.bind(this);
+ this.addAuditsChangeListener = this.addAuditsChangeListener.bind(this);
+ this.removeAuditsChangeListener = this.removeAuditsChangeListener.bind(this);
+ this.emitTeamsChange = this.emitTeamsChange.bind(this);
+ this.addTeamsChangeListener = this.addTeamsChangeListener.bind(this);
+ this.removeTeamsChangeListener = this.removeTeamsChangeListener.bind(this);
+ this.emitStatusesChange = this.emitStatusesChange.bind(this);
+ this.addStatusesChangeListener = this.addStatusesChangeListener.bind(this);
+ this.removeStatusesChangeListener = this.removeStatusesChangeListener.bind(this);
+ this.setCurrentId = this.setCurrentId.bind(this);
+ this.getCurrentId = this.getCurrentId.bind(this);
+ this.getCurrentUser = this.getCurrentUser.bind(this);
+ this.setCurrentUser = this.setCurrentUser.bind(this);
+ this.getLastEmail = this.getLastEmail.bind(this);
+ this.setLastEmail = this.setLastEmail.bind(this);
+ this.removeCurrentUser = this.removeCurrentUser.bind(this);
+ this.hasProfile = this.hasProfile.bind(this);
+ this.getProfile = this.getProfile.bind(this);
+ this.getProfileByUsername = this.getProfileByUsername.bind(this);
+ this.getProfilesUsernameMap = this.getProfilesUsernameMap.bind(this);
+ this.getProfiles = this.getProfiles.bind(this);
+ this.getActiveOnlyProfiles = this.getActiveOnlyProfiles.bind(this);
+ this.saveProfile = this.saveProfile.bind(this);
+ this.pStoreProfiles = this.pStoreProfiles.bind(this);
+ this.pGetProfiles = this.pGetProfiles.bind(this);
+ this.pGetProfilesUsernameMap = this.pGetProfilesUsernameMap.bind(this);
+ this.setSessions = this.setSessions.bind(this);
+ this.getSessions = this.getSessions.bind(this);
+ this.setAudits = this.setAudits.bind(this);
+ this.getAudits = this.getAudits.bind(this);
+ this.setTeams = this.setTeams.bind(this);
+ this.getTeams = this.getTeams.bind(this);
+ this.getCurrentMentionKeys = this.getCurrentMentionKeys.bind(this);
+ this.getLastVersion = this.getLastVersion.bind(this);
+ this.setLastVersion = this.setLastVersion.bind(this);
+ this.setStatuses = this.setStatuses.bind(this);
+ this.pSetStatuses = this.pSetStatuses.bind(this);
+ this.setStatus = this.setStatus.bind(this);
+ this.getStatuses = this.getStatuses.bind(this);
+ this.getStatus = this.getStatus.bind(this);
- emitChange: function(userId) {
+ this.gCurrentId = null;
+ }
+
+ emitChange(userId) {
this.emit(CHANGE_EVENT, userId);
- },
- addChangeListener: function(callback) {
+ }
+ addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function(callback) {
+ }
+ removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
- },
- emitSessionsChange: function() {
+ }
+ emitSessionsChange() {
this.emit(CHANGE_EVENT_SESSIONS);
- },
- addSessionsChangeListener: function(callback) {
+ }
+ addSessionsChangeListener(callback) {
this.on(CHANGE_EVENT_SESSIONS, callback);
- },
- removeSessionsChangeListener: function(callback) {
+ }
+ removeSessionsChangeListener(callback) {
this.removeListener(CHANGE_EVENT_SESSIONS, callback);
- },
- emitAuditsChange: function() {
+ }
+ emitAuditsChange() {
this.emit(CHANGE_EVENT_AUDITS);
- },
- addAuditsChangeListener: function(callback) {
+ }
+ addAuditsChangeListener(callback) {
this.on(CHANGE_EVENT_AUDITS, callback);
- },
- removeAuditsChangeListener: function(callback) {
+ }
+ removeAuditsChangeListener(callback) {
this.removeListener(CHANGE_EVENT_AUDITS, callback);
- },
- emitTeamsChange: function() {
+ }
+ emitTeamsChange() {
this.emit(CHANGE_EVENT_TEAMS);
- },
- addTeamsChangeListener: function(callback) {
+ }
+ addTeamsChangeListener(callback) {
this.on(CHANGE_EVENT_TEAMS, callback);
- },
- removeTeamsChangeListener: function(callback) {
+ }
+ removeTeamsChangeListener(callback) {
this.removeListener(CHANGE_EVENT_TEAMS, callback);
- },
- emitStatusesChange: function() {
+ }
+ emitStatusesChange() {
this.emit(CHANGE_EVENT_STATUSES);
- },
- addStatusesChangeListener: function(callback) {
+ }
+ addStatusesChangeListener(callback) {
this.on(CHANGE_EVENT_STATUSES, callback);
- },
- removeStatusesChangeListener: function(callback) {
+ }
+ removeStatusesChangeListener(callback) {
this.removeListener(CHANGE_EVENT_STATUSES, callback);
- },
- setCurrentId: function(id) {
+ }
+ setCurrentId(id) {
this.gCurrentId = id;
if (id == null) {
BrowserStore.removeGlobalItem('current_user_id');
} else {
BrowserStore.setGlobalItem('current_user_id', id);
}
- },
- getCurrentId: function(skipFetch) {
+ }
+ getCurrentId(skipFetch) {
var currentId = this.gCurrentId;
if (currentId == null) {
@@ -93,46 +142,45 @@ var UserStore = assign({}, EventEmitter.prototype, {
}
return currentId;
- },
- getCurrentUser: function() {
+ }
+ getCurrentUser() {
if (this.getCurrentId() == null) {
return null;
}
- return this._getProfiles()[this.getCurrentId()];
- },
- setCurrentUser: function(user) {
+ return this.pGetProfiles()[this.getCurrentId()];
+ }
+ setCurrentUser(user) {
this.setCurrentId(user.id);
this.saveProfile(user);
- },
- getLastEmail: function() {
+ }
+ getLastEmail() {
return BrowserStore.getItem('last_email', '');
- },
- setLastEmail: function(email) {
+ }
+ setLastEmail(email) {
BrowserStore.setItem('last_email', email);
- },
- removeCurrentUser: function() {
+ }
+ removeCurrentUser() {
this.setCurrentId(null);
- },
- hasProfile: function(userId) {
- return this._getProfiles()[userId] != null;
- },
- getProfile: function(userId) {
- return this._getProfiles()[userId];
- },
- getProfileByUsername: function(username) {
- return this._getProfilesUsernameMap()[username];
- },
- getProfilesUsernameMap: function() {
- return this._getProfilesUsernameMap();
- },
- getProfiles: function() {
-
- return this._getProfiles();
- },
- getActiveOnlyProfiles: function() {
+ }
+ hasProfile(userId) {
+ return this.pGetProfiles()[userId] != null;
+ }
+ getProfile(userId) {
+ return this.pGetProfiles()[userId];
+ }
+ getProfileByUsername(username) {
+ return this.pGetProfilesUsernameMap()[username];
+ }
+ getProfilesUsernameMap() {
+ return this.pGetProfilesUsernameMap();
+ }
+ getProfiles() {
+ return this.pGetProfiles();
+ }
+ getActiveOnlyProfiles() {
var active = {};
- var current = this._getProfiles();
+ var current = this.pGetProfiles();
for (var key in current) {
if (current[key].delete_at === 0) {
@@ -141,45 +189,47 @@ var UserStore = assign({}, EventEmitter.prototype, {
}
return active;
- },
- saveProfile: function(profile) {
- var ps = this._getProfiles();
+ }
+ saveProfile(profile) {
+ var ps = this.pGetProfiles();
ps[profile.id] = profile;
- this._storeProfiles(ps);
- },
- _storeProfiles: function(profiles) {
+ this.pStoreProfiles(ps);
+ }
+ pStoreProfiles(profiles) {
BrowserStore.setItem('profiles', profiles);
var profileUsernameMap = {};
for (var id in profiles) {
- profileUsernameMap[profiles[id].username] = profiles[id];
+ if (profiles.hasOwnProperty(id)) {
+ profileUsernameMap[profiles[id].username] = profiles[id];
+ }
}
BrowserStore.setItem('profileUsernameMap', profileUsernameMap);
- },
- _getProfiles: function() {
+ }
+ pGetProfiles() {
return BrowserStore.getItem('profiles', {});
- },
- _getProfilesUsernameMap: function() {
+ }
+ pGetProfilesUsernameMap() {
return BrowserStore.getItem('profileUsernameMap', {});
- },
- setSessions: function(sessions) {
+ }
+ setSessions(sessions) {
BrowserStore.setItem('sessions', sessions);
- },
- getSessions: function() {
+ }
+ getSessions() {
return BrowserStore.getItem('sessions', {loading: true});
- },
- setAudits: function(audits) {
+ }
+ setAudits(audits) {
BrowserStore.setItem('audits', audits);
- },
- getAudits: function() {
+ }
+ getAudits() {
return BrowserStore.getItem('audits', {loading: true});
- },
- setTeams: function(teams) {
+ }
+ setTeams(teams) {
BrowserStore.setItem('teams', teams);
- },
- getTeams: function() {
+ }
+ getTeams() {
return BrowserStore.getItem('teams', []);
- },
- getCurrentMentionKeys: function() {
+ }
+ getCurrentMentionKeys() {
var user = this.getCurrentUser();
var keys = [];
@@ -205,74 +255,76 @@ var UserStore = assign({}, EventEmitter.prototype, {
}
return keys;
- },
- getLastVersion: function() {
+ }
+ getLastVersion() {
return BrowserStore.getItem('last_version', '');
- },
- setLastVersion: function(version) {
+ }
+ setLastVersion(version) {
BrowserStore.setItem('last_version', version);
- },
- setStatuses: function(statuses) {
- this._setStatuses(statuses);
+ }
+ setStatuses(statuses) {
+ this.pSetStatuses(statuses);
this.emitStatusesChange();
- },
- _setStatuses: function(statuses) {
+ }
+ pSetStatuses(statuses) {
BrowserStore.setItem('statuses', statuses);
- },
- setStatus: function(userId, status) {
+ }
+ setStatus(userId, status) {
var statuses = this.getStatuses();
statuses[userId] = status;
- this._setStatuses(statuses);
+ this.pSetStatuses(statuses);
this.emitStatusesChange();
- },
- getStatuses: function() {
+ }
+ getStatuses() {
return BrowserStore.getItem('statuses', {});
- },
- getStatus: function(id) {
+ }
+ getStatus(id) {
return this.getStatuses()[id];
}
-});
+}
+
+var UserStore = new UserStoreClass();
+UserStore.setMaxListeners(0);
-UserStore.dispatchToken = AppDispatcher.register(function(payload) {
+UserStore.dispatchToken = AppDispatcher.register(function registry(payload) {
var action = payload.action;
switch (action.type) {
- case ActionTypes.RECIEVED_PROFILES:
- for (var id in action.profiles) {
- // profiles can have incomplete data, so don't overwrite current user
- if (id === UserStore.getCurrentId()) {
- continue;
- }
- var profile = action.profiles[id];
- UserStore.saveProfile(profile);
- UserStore.emitChange(profile.id);
+ case ActionTypes.RECIEVED_PROFILES:
+ for (var id in action.profiles) {
+ // profiles can have incomplete data, so don't overwrite current user
+ if (id === UserStore.getCurrentId()) {
+ continue;
}
- break;
- case ActionTypes.RECIEVED_ME:
- UserStore.setCurrentUser(action.me);
- UserStore.emitChange(action.me.id);
- break;
- case ActionTypes.RECIEVED_SESSIONS:
- UserStore.setSessions(action.sessions);
- UserStore.emitSessionsChange();
- break;
- case ActionTypes.RECIEVED_AUDITS:
- UserStore.setAudits(action.audits);
- UserStore.emitAuditsChange();
- break;
- case ActionTypes.RECIEVED_TEAMS:
- UserStore.setTeams(action.teams);
- UserStore.emitTeamsChange();
- break;
- case ActionTypes.RECIEVED_STATUSES:
- UserStore._setStatuses(action.statuses);
- UserStore.emitStatusesChange();
- break;
+ var profile = action.profiles[id];
+ UserStore.saveProfile(profile);
+ UserStore.emitChange(profile.id);
+ }
+ break;
+ case ActionTypes.RECIEVED_ME:
+ UserStore.setCurrentUser(action.me);
+ UserStore.emitChange(action.me.id);
+ break;
+ case ActionTypes.RECIEVED_SESSIONS:
+ UserStore.setSessions(action.sessions);
+ UserStore.emitSessionsChange();
+ break;
+ case ActionTypes.RECIEVED_AUDITS:
+ UserStore.setAudits(action.audits);
+ UserStore.emitAuditsChange();
+ break;
+ case ActionTypes.RECIEVED_TEAMS:
+ UserStore.setTeams(action.teams);
+ UserStore.emitTeamsChange();
+ break;
+ case ActionTypes.RECIEVED_STATUSES:
+ UserStore.pSetStatuses(action.statuses);
+ UserStore.emitStatusesChange();
+ break;
- default:
+ default:
}
});
-UserStore.setMaxListeners(0);
global.window.UserStore = UserStore;
-module.exports = UserStore;
+export default UserStore;