2015-03-07 01:37:24 +08:00
|
|
|
import Store from "discourse/models/store";
|
2018-06-15 23:03:24 +08:00
|
|
|
import RestAdapter from "discourse/adapters/rest";
|
|
|
|
import KeyValueStore from "discourse/lib/key-value-store";
|
|
|
|
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
|
|
|
import { buildResolver } from "discourse-common/resolver";
|
2015-03-07 01:37:24 +08:00
|
|
|
|
|
|
|
export default function() {
|
2018-06-15 23:03:24 +08:00
|
|
|
const resolver = buildResolver("discourse").create();
|
2016-11-09 02:40:35 +08:00
|
|
|
|
2015-03-07 01:37:24 +08:00
|
|
|
return Store.create({
|
2016-11-09 02:40:35 +08:00
|
|
|
register: {
|
2015-03-07 01:37:24 +08:00
|
|
|
lookup(type) {
|
|
|
|
if (type === "adapter:rest") {
|
2017-06-15 01:57:58 +08:00
|
|
|
if (!this._restAdapter) {
|
|
|
|
this._restAdapter = RestAdapter.create({ owner: this });
|
|
|
|
}
|
|
|
|
return this._restAdapter;
|
2015-09-04 04:55:55 +08:00
|
|
|
}
|
|
|
|
if (type === "key-value-store:main") {
|
|
|
|
this._kvs = this._kvs || new KeyValueStore();
|
2018-06-15 23:03:24 +08:00
|
|
|
return this._kvs;
|
2015-09-04 04:55:55 +08:00
|
|
|
}
|
|
|
|
if (type === "topic-tracking-state:main") {
|
2015-09-22 02:15:25 +08:00
|
|
|
this._tracker = this._tracker || TopicTrackingState.create();
|
2018-06-15 23:03:24 +08:00
|
|
|
return this._tracker;
|
2015-09-04 04:55:55 +08:00
|
|
|
}
|
|
|
|
if (type === "site-settings:main") {
|
2016-06-15 02:31:51 +08:00
|
|
|
this._settings = this._settings || Discourse.SiteSettings;
|
2018-06-15 23:03:24 +08:00
|
|
|
return this._settings;
|
2015-03-07 01:37:24 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-04-09 02:44:44 +08:00
|
|
|
lookupFactory(type) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const split = type.split(":");
|
|
|
|
return resolver.customResolve({
|
|
|
|
type: split[0],
|
|
|
|
fullNameWithoutType: split[1]
|
|
|
|
});
|
|
|
|
}
|
2015-03-07 01:37:24 +08:00
|
|
|
}
|
|
|
|
});
|
2017-09-06 22:21:07 +08:00
|
|
|
}
|