discourse/test/javascripts/helpers/create-store.js.es6

49 lines
1.5 KiB
Plaintext
Raw Normal View History

2015-03-06 12:37:24 -05:00
import Store from "discourse/models/store";
2018-06-15 11:03:24 -04:00
import RestAdapter from "discourse/adapters/rest";
import KeyValueStore from "discourse/lib/key-value-store";
import TopicListAdapter from "discourse/adapters/topic-list";
2018-06-15 11:03:24 -04:00
import TopicTrackingState from "discourse/models/topic-tracking-state";
import { buildResolver } from "discourse-common/resolver";
2015-03-06 12:37:24 -05:00
export default function() {
2018-06-15 11:03:24 -04:00
const resolver = buildResolver("discourse").create();
2015-03-06 12:37:24 -05:00
return Store.create({
register: {
2015-03-06 12:37:24 -05:00
lookup(type) {
if (type === "adapter:rest") {
2017-06-14 13:57:58 -04:00
if (!this._restAdapter) {
this._restAdapter = RestAdapter.create({ owner: this });
}
return this._restAdapter;
}
if (type === "adapter:topicList") {
this._topicListAdapter =
this._topicListAdapter || TopicListAdapter.create({ owner: this });
return this._topicListAdapter;
}
if (type === "key-value-store:main") {
this._kvs = this._kvs || new KeyValueStore();
2018-06-15 11:03:24 -04:00
return this._kvs;
}
if (type === "topic-tracking-state:main") {
this._tracker = this._tracker || TopicTrackingState.create();
2018-06-15 11:03:24 -04:00
return this._tracker;
}
if (type === "site-settings:main") {
this._settings = this._settings || Discourse.SiteSettings;
2018-06-15 11:03:24 -04:00
return this._settings;
2015-03-06 12:37:24 -05:00
}
},
lookupFactory(type) {
2018-06-15 11:03:24 -04:00
const split = type.split(":");
return resolver.customResolve({
type: split[0],
fullNameWithoutType: split[1]
});
}
2015-03-06 12:37:24 -05:00
}
});
2017-09-06 10:21:07 -04:00
}