FIX: Load order of TopicTrackingState was off

This commit is contained in:
Robin Ward 2015-09-21 14:15:25 -04:00
parent 9f6ce653a9
commit b49e9fb174
4 changed files with 20 additions and 33 deletions

View file

@ -137,13 +137,10 @@ const Category = RestModel.extend({
}.property('topics'), }.property('topics'),
unreadTopics: function() { unreadTopics: function() {
// TODO this is somehow null for /categories page anon
if (!this.topicTrackingState) { return 0; }
return this.topicTrackingState.countUnread(this.get('id')); return this.topicTrackingState.countUnread(this.get('id'));
}.property('topicTrackingState.messageCount'), }.property('topicTrackingState.messageCount'),
newTopics: function() { newTopics: function() {
if (!this.topicTrackingState) { return 0; }
return this.topicTrackingState.countNew(this.get('id')); return this.topicTrackingState.countNew(this.get('id'));
}.property('topicTrackingState.messageCount'), }.property('topicTrackingState.messageCount'),

View file

@ -336,32 +336,16 @@ const TopicTrackingState = Discourse.Model.extend({
}); });
} }
} }
}); });
export function startTracking(tracking) {
TopicTrackingState.reopenClass({ const data = PreloadStore.get('topicTrackingStates');
tracking.loadStates(data);
createFromStates(data) { tracking.initialStatesLength = data && data.length;
// TODO: This should be a model that does injection automatically tracking.establishChannels();
const container = Discourse.__container__, PreloadStore.remove('topicTrackingStates');
messageBus = container.lookup('message-bus:main'), }
currentUser = container.lookup('current-user:main'),
instance = TopicTrackingState.create({ messageBus, currentUser });
instance.loadStates(data);
instance.initialStatesLength = data && data.length;
instance.establishChannels();
return instance;
},
current() {
if (!this.tracker) {
const data = PreloadStore.get('topicTrackingStates');
this.tracker = this.createFromStates(data);
PreloadStore.remove('topicTrackingStates');
}
return this.tracker;
}
});
export default TopicTrackingState; export default TopicTrackingState;

View file

@ -5,7 +5,7 @@ import Store from 'discourse/models/store';
import DiscourseURL from 'discourse/lib/url'; import DiscourseURL from 'discourse/lib/url';
import DiscourseLocation from 'discourse/lib/discourse-location'; import DiscourseLocation from 'discourse/lib/discourse-location';
import SearchService from 'discourse/services/search'; import SearchService from 'discourse/services/search';
import TopicTrackingState from 'discourse/models/topic-tracking-state'; import { startTracking, default as TopicTrackingState } from 'discourse/models/topic-tracking-state';
function inject() { function inject() {
const app = arguments[0], const app = arguments[0],
@ -31,11 +31,15 @@ export default {
app.register('store:main', Store); app.register('store:main', Store);
inject(app, 'store', 'route', 'controller'); inject(app, 'store', 'route', 'controller');
app.register('message-bus:main', window.MessageBus, { instantiate: false }); const messageBus = window.MessageBus;
app.register('message-bus:main', messageBus, { instantiate: false });
injectAll(app, 'messageBus'); injectAll(app, 'messageBus');
app.register('current-user:main', Discourse.User.current(), { instantiate: false }); const currentUser = Discourse.User.current();
app.register('topic-tracking-state:main', TopicTrackingState.current(), { instantiate: false }); app.register('current-user:main', currentUser, { instantiate: false });
const tracking = TopicTrackingState.create({ messageBus, currentUser });
app.register('topic-tracking-state:main', tracking, { instantiate: false });
injectAll(app, 'topicTrackingState'); injectAll(app, 'topicTrackingState');
const site = Discourse.Site.current(); const site = Discourse.Site.current();
@ -58,5 +62,7 @@ export default {
const keyValueStore = new KeyValueStore("discourse_"); const keyValueStore = new KeyValueStore("discourse_");
app.register('key-value-store:main', keyValueStore, { instantiate: false }); app.register('key-value-store:main', keyValueStore, { instantiate: false });
injectAll(app, 'keyValueStore'); injectAll(app, 'keyValueStore');
startTracking(tracking);
} }
}; };

View file

@ -18,7 +18,7 @@ export default function() {
return (this._kvs); return (this._kvs);
} }
if (type === "topic-tracking-state:main") { if (type === "topic-tracking-state:main") {
this._tracker = this._tracker || TopicTrackingState.current(); this._tracker = this._tracker || TopicTrackingState.create();
return (this._tracker); return (this._tracker);
} }
if (type === "site-settings:main") { if (type === "site-settings:main") {