REFACTOR: Rename `store:main` to `service:store` so we can inject it

This commit is contained in:
Robin Ward 2017-10-27 13:59:22 -04:00
parent f2219138e1
commit fbd5f1e411
11 changed files with 34 additions and 33 deletions

View File

@ -33,7 +33,7 @@ export default {
}
bus.subscribe(`/notification/${user.get('id')}`, data => {
const store = container.lookup('store:main');
const store = container.lookup('service:store');
const oldUnread = user.get('unread_notifications');
const oldPM = user.get('unread_private_messages');

View File

@ -441,7 +441,7 @@ class PluginApi {
* will issue a request to `/mice.json`
**/
addStorePluralization(thing, plural) {
this.container.lookup("store:main").addPluralization(thing, plural);
this.container.lookup("service:store").addPluralization(thing, plural);
}
/**

View File

@ -122,7 +122,7 @@ NavItem.reopenClass({
_.merge(args, extra);
});
const store = Discourse.__container__.lookup('store:main');
const store = Discourse.__container__.lookup('service:store');
return store.createRecord('nav-item', args);
},

View File

@ -84,7 +84,7 @@ RestModel.reopenClass({
if (!args.store) {
const container = Discourse.__container__;
// Ember.warn('Use `store.createRecord` to create records instead of `.create()`');
args.store = container.lookup('store:main');
args.store = container.lookup('service:store');
}
args.__munge = this.munge;

View File

@ -94,7 +94,7 @@ Site.reopenClass(Singleton, {
// The current singleton will retrieve its attributes from the `PreloadStore`.
createCurrent() {
const store = Discourse.__container__.lookup('store:main');
const store = Discourse.__container__.lookup('service:store');
return store.createRecord('site', PreloadStore.get('site'));
},

View File

@ -140,7 +140,7 @@ TopicList.reopenClass({
},
find(filter, params) {
const store = Discourse.__container__.lookup('store:main');
const store = Discourse.__container__.lookup('service:store');
return store.findFiltered('topicList', {filter, params});
},

View File

@ -544,7 +544,7 @@ User.reopenClass(Singleton, {
createCurrent() {
const userJson = PreloadStore.get('currentUser');
if (userJson) {
const store = Discourse.__container__.lookup('store:main');
const store = Discourse.__container__.lookup('service:store');
return store.createRecord('user', userJson);
}
return null;

View File

@ -8,17 +8,7 @@ import SearchService from 'discourse/services/search';
import { startTracking, default as TopicTrackingState } from 'discourse/models/topic-tracking-state';
import ScreenTrack from 'discourse/lib/screen-track';
function inject() {
const app = arguments[0],
name = arguments[1],
singletonName = Ember.String.underscore(name).replace(/_/g, '-') + ':main';
Array.prototype.slice.call(arguments, 2).forEach(dest => app.inject(dest, name, singletonName));
}
function injectAll(app, name) {
inject(app, name, 'controller', 'component', 'route', 'model', 'adapter');
}
const ALL_TARGETS = ['controller', 'component', 'route', 'model', 'adapter'];
export default {
name: "inject-discourse-objects",
@ -26,51 +16,62 @@ export default {
initialize(container, app) {
const appEvents = AppEvents.create();
app.register('app-events:main', appEvents, { instantiate: false });
injectAll(app, 'appEvents');
ALL_TARGETS.forEach(t => app.inject(t, 'appEvents', 'app-events:main'));
DiscourseURL.appEvents = appEvents;
// backwards compatibility: remove when plugins have updated
app.register('store:main', Store);
inject(app, 'store', 'route', 'controller', 'service');
app.register('service:store', Store);
ALL_TARGETS.forEach(t => app.inject(t, 'store', 'service:store'));
const messageBus = window.MessageBus;
app.register('message-bus:main', messageBus, { instantiate: false });
injectAll(app, 'messageBus');
ALL_TARGETS.forEach(t => app.inject(t, 'messageBus', 'message-bus:main'));
const currentUser = Discourse.User.current();
app.register('current-user:main', currentUser, { instantiate: false });
const topicTrackingState = TopicTrackingState.create({ messageBus, currentUser });
app.register('topic-tracking-state:main', topicTrackingState, { instantiate: false });
injectAll(app, 'topicTrackingState');
ALL_TARGETS.forEach(t => app.inject(t, 'topicTrackingState', 'topic-tracking-state:main'));
const site = Discourse.Site.current();
app.register('site:main', site, { instantiate: false });
injectAll(app, 'site');
ALL_TARGETS.forEach(t => app.inject(t, 'site', 'site:main'));
const siteSettings = Discourse.SiteSettings;
app.register('site-settings:main', siteSettings, { instantiate: false });
injectAll(app, 'siteSettings');
ALL_TARGETS.forEach(t => app.inject(t, 'siteSettings', 'site-settings:main'));
app.register('search-service:main', SearchService);
injectAll(app, 'searchService');
ALL_TARGETS.forEach(t => app.inject(t, 'searchService', 'search-service:main'));
const session = Session.current();
app.register('session:main', session, { instantiate: false });
injectAll(app, 'session');
ALL_TARGETS.forEach(t => app.inject(t, 'session', 'session:main'));
const screenTrack = new ScreenTrack(
topicTrackingState,
siteSettings,
session,
currentUser
);
const screenTrack = new ScreenTrack(topicTrackingState, siteSettings, session, currentUser);
app.register('screen-track:main', screenTrack, { instantiate: false });
inject(app, 'screenTrack', 'component', 'route');
['component', 'route'].forEach(t => app.inject(t, 'screenTrack', 'screen-track:main'));
if (currentUser) {
inject(app, 'currentUser', 'component', 'route', 'controller');
['component', 'route', 'controller'].forEach(t => {
app.inject(t, 'currentUser', 'current-user:main');
});
}
app.register('location:discourse-location', DiscourseLocation);
const keyValueStore = new KeyValueStore("discourse_");
app.register('key-value-store:main', keyValueStore, { instantiate: false });
injectAll(app, 'keyValueStore');
ALL_TARGETS.forEach(t => app.inject(t, 'keyValueStore', 'key-value-store:main'));
startTracking(topicTrackingState);
}

View File

@ -153,7 +153,7 @@ export default class Widget {
this.siteSettings = register.lookup('site-settings:main');
this.currentUser = register.lookup('current-user:main');
this.capabilities = register.lookup('capabilities:main');
this.store = register.lookup('store:main');
this.store = register.lookup('service:store');
this.appEvents = register.lookup('app-events:main');
this.keyValueStore = register.lookup('key-value-store:main');

View File

@ -33,7 +33,7 @@ export default function(name, opts) {
{ instantiate: false });
}
this.registry.register('store:main', store, { instantiate: false });
this.registry.register('service:store', store, { instantiate: false });
if (opts.beforeEach) {
opts.beforeEach.call(this, store);

View File

@ -1,4 +1,4 @@
QUnit.module('store:main');
QUnit.module('service:store');
import createStore from 'helpers/create-store';