mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
REFACTOR: Rename store:main
to service:store
so we can inject it
This commit is contained in:
@ -33,7 +33,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bus.subscribe(`/notification/${user.get('id')}`, data => {
|
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 oldUnread = user.get('unread_notifications');
|
||||||
const oldPM = user.get('unread_private_messages');
|
const oldPM = user.get('unread_private_messages');
|
||||||
|
@ -441,7 +441,7 @@ class PluginApi {
|
|||||||
* will issue a request to `/mice.json`
|
* will issue a request to `/mice.json`
|
||||||
**/
|
**/
|
||||||
addStorePluralization(thing, plural) {
|
addStorePluralization(thing, plural) {
|
||||||
this.container.lookup("store:main").addPluralization(thing, plural);
|
this.container.lookup("service:store").addPluralization(thing, plural);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,7 +122,7 @@ NavItem.reopenClass({
|
|||||||
_.merge(args, extra);
|
_.merge(args, extra);
|
||||||
});
|
});
|
||||||
|
|
||||||
const store = Discourse.__container__.lookup('store:main');
|
const store = Discourse.__container__.lookup('service:store');
|
||||||
return store.createRecord('nav-item', args);
|
return store.createRecord('nav-item', args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ RestModel.reopenClass({
|
|||||||
if (!args.store) {
|
if (!args.store) {
|
||||||
const container = Discourse.__container__;
|
const container = Discourse.__container__;
|
||||||
// Ember.warn('Use `store.createRecord` to create records instead of `.create()`');
|
// 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;
|
args.__munge = this.munge;
|
||||||
|
@ -94,7 +94,7 @@ Site.reopenClass(Singleton, {
|
|||||||
|
|
||||||
// The current singleton will retrieve its attributes from the `PreloadStore`.
|
// The current singleton will retrieve its attributes from the `PreloadStore`.
|
||||||
createCurrent() {
|
createCurrent() {
|
||||||
const store = Discourse.__container__.lookup('store:main');
|
const store = Discourse.__container__.lookup('service:store');
|
||||||
return store.createRecord('site', PreloadStore.get('site'));
|
return store.createRecord('site', PreloadStore.get('site'));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ TopicList.reopenClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
find(filter, params) {
|
find(filter, params) {
|
||||||
const store = Discourse.__container__.lookup('store:main');
|
const store = Discourse.__container__.lookup('service:store');
|
||||||
return store.findFiltered('topicList', {filter, params});
|
return store.findFiltered('topicList', {filter, params});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -544,7 +544,7 @@ User.reopenClass(Singleton, {
|
|||||||
createCurrent() {
|
createCurrent() {
|
||||||
const userJson = PreloadStore.get('currentUser');
|
const userJson = PreloadStore.get('currentUser');
|
||||||
if (userJson) {
|
if (userJson) {
|
||||||
const store = Discourse.__container__.lookup('store:main');
|
const store = Discourse.__container__.lookup('service:store');
|
||||||
return store.createRecord('user', userJson);
|
return store.createRecord('user', userJson);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -8,17 +8,7 @@ import SearchService from 'discourse/services/search';
|
|||||||
import { startTracking, default as TopicTrackingState } from 'discourse/models/topic-tracking-state';
|
import { startTracking, default as TopicTrackingState } from 'discourse/models/topic-tracking-state';
|
||||||
import ScreenTrack from 'discourse/lib/screen-track';
|
import ScreenTrack from 'discourse/lib/screen-track';
|
||||||
|
|
||||||
function inject() {
|
const ALL_TARGETS = ['controller', 'component', 'route', 'model', 'adapter'];
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "inject-discourse-objects",
|
name: "inject-discourse-objects",
|
||||||
@ -26,51 +16,62 @@ export default {
|
|||||||
initialize(container, app) {
|
initialize(container, app) {
|
||||||
const appEvents = AppEvents.create();
|
const appEvents = AppEvents.create();
|
||||||
app.register('app-events:main', appEvents, { instantiate: false });
|
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;
|
DiscourseURL.appEvents = appEvents;
|
||||||
|
|
||||||
|
// backwards compatibility: remove when plugins have updated
|
||||||
app.register('store:main', Store);
|
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;
|
const messageBus = window.MessageBus;
|
||||||
app.register('message-bus:main', messageBus, { instantiate: false });
|
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();
|
const currentUser = Discourse.User.current();
|
||||||
app.register('current-user:main', currentUser, { instantiate: false });
|
app.register('current-user:main', currentUser, { instantiate: false });
|
||||||
|
|
||||||
const topicTrackingState = TopicTrackingState.create({ messageBus, currentUser });
|
const topicTrackingState = TopicTrackingState.create({ messageBus, currentUser });
|
||||||
app.register('topic-tracking-state:main', topicTrackingState, { instantiate: false });
|
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();
|
const site = Discourse.Site.current();
|
||||||
app.register('site:main', site, { instantiate: false });
|
app.register('site:main', site, { instantiate: false });
|
||||||
injectAll(app, 'site');
|
ALL_TARGETS.forEach(t => app.inject(t, 'site', 'site:main'));
|
||||||
|
|
||||||
const siteSettings = Discourse.SiteSettings;
|
const siteSettings = Discourse.SiteSettings;
|
||||||
app.register('site-settings:main', siteSettings, { instantiate: false });
|
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);
|
app.register('search-service:main', SearchService);
|
||||||
injectAll(app, 'searchService');
|
ALL_TARGETS.forEach(t => app.inject(t, 'searchService', 'search-service:main'));
|
||||||
|
|
||||||
const session = Session.current();
|
const session = Session.current();
|
||||||
app.register('session:main', session, { instantiate: false });
|
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 });
|
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) {
|
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);
|
app.register('location:discourse-location', DiscourseLocation);
|
||||||
|
|
||||||
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');
|
ALL_TARGETS.forEach(t => app.inject(t, 'keyValueStore', 'key-value-store:main'));
|
||||||
|
|
||||||
startTracking(topicTrackingState);
|
startTracking(topicTrackingState);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ export default class Widget {
|
|||||||
this.siteSettings = register.lookup('site-settings:main');
|
this.siteSettings = register.lookup('site-settings:main');
|
||||||
this.currentUser = register.lookup('current-user:main');
|
this.currentUser = register.lookup('current-user:main');
|
||||||
this.capabilities = register.lookup('capabilities: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.appEvents = register.lookup('app-events:main');
|
||||||
this.keyValueStore = register.lookup('key-value-store:main');
|
this.keyValueStore = register.lookup('key-value-store:main');
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export default function(name, opts) {
|
|||||||
{ instantiate: false });
|
{ instantiate: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.registry.register('store:main', store, { instantiate: false });
|
this.registry.register('service:store', store, { instantiate: false });
|
||||||
|
|
||||||
if (opts.beforeEach) {
|
if (opts.beforeEach) {
|
||||||
opts.beforeEach.call(this, store);
|
opts.beforeEach.call(this, store);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
QUnit.module('store:main');
|
QUnit.module('service:store');
|
||||||
|
|
||||||
import createStore from 'helpers/create-store';
|
import createStore from 'helpers/create-store';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user