2015-03-07 01:37:24 +08:00
|
|
|
import Store from "discourse/models/store";
|
|
|
|
import RestAdapter from "discourse/adapters/rest";
|
2015-09-04 04:55:55 +08:00
|
|
|
import KeyValueStore from "discourse/lib/key-value-store";
|
2019-09-09 23:03:57 +08:00
|
|
|
import TopicListAdapter from "discourse/adapters/topic-list";
|
2015-09-04 04:55:55 +08:00
|
|
|
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
2016-08-31 23:30:51 +08:00
|
|
|
import { buildResolver } from "discourse-common/resolver";
|
2020-07-15 01:07:54 +08:00
|
|
|
import { currentSettings } from "helpers/site-settings";
|
2015-03-07 01:37:24 +08:00
|
|
|
|
2020-03-30 21:23:59 +08:00
|
|
|
const CatAdapter = RestAdapter.extend({
|
|
|
|
primaryKey: "cat_id"
|
|
|
|
});
|
|
|
|
|
2019-10-30 23:25:42 +08:00
|
|
|
export default function(customLookup = () => {}) {
|
2016-08-31 23:30:51 +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) {
|
2020-03-30 21:23:59 +08:00
|
|
|
if (type === "adapter:cat") {
|
|
|
|
this._catAdapter =
|
|
|
|
this._catAdapter || CatAdapter.create({ owner: this });
|
|
|
|
return this._catAdapter;
|
|
|
|
}
|
2015-03-07 01:37:24 +08:00
|
|
|
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
|
|
|
}
|
2019-09-09 23:03:57 +08:00
|
|
|
if (type === "adapter:topicList") {
|
|
|
|
this._topicListAdapter =
|
|
|
|
this._topicListAdapter || TopicListAdapter.create({ owner: this });
|
|
|
|
return this._topicListAdapter;
|
|
|
|
}
|
2015-09-04 04:55:55 +08:00
|
|
|
if (type === "key-value-store:main") {
|
|
|
|
this._kvs = this._kvs || new KeyValueStore();
|
|
|
|
return this._kvs;
|
|
|
|
}
|
|
|
|
if (type === "topic-tracking-state:main") {
|
2015-09-22 02:15:25 +08:00
|
|
|
this._tracker = this._tracker || TopicTrackingState.create();
|
2015-09-04 04:55:55 +08:00
|
|
|
return this._tracker;
|
|
|
|
}
|
|
|
|
if (type === "site-settings:main") {
|
2020-07-15 01:07:54 +08:00
|
|
|
this._settings = this._settings || currentSettings();
|
2015-09-04 04:55:55 +08:00
|
|
|
return this._settings;
|
2015-03-07 01:37:24 +08:00
|
|
|
}
|
2019-10-30 23:25:42 +08:00
|
|
|
return customLookup(type);
|
2015-03-07 01:37:24 +08:00
|
|
|
},
|
|
|
|
|
2015-04-09 02:44:44 +08:00
|
|
|
lookupFactory(type) {
|
|
|
|
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
|
|
|
}
|