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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-03-07 01:37:24 +08:00
import Store from "discourse/models/store";
import RestAdapter from "discourse/adapters/rest";
import KeyValueStore from "discourse/lib/key-value-store";
import TopicListAdapter from "discourse/adapters/topic-list";
import TopicTrackingState from "discourse/models/topic-tracking-state";
import { buildResolver } from "discourse-common/resolver";
import { currentSettings } from "helpers/site-settings";
2015-03-07 01:37:24 +08:00
const CatAdapter = RestAdapter.extend({
primaryKey: "cat_id"
});
export default function(customLookup = () => {}) {
const resolver = buildResolver("discourse").create();
2015-03-07 01:37:24 +08:00
return Store.create({
register: {
2015-03-07 01:37:24 +08:00
lookup(type) {
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;
}
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();
return this._kvs;
}
if (type === "topic-tracking-state:main") {
this._tracker = this._tracker || TopicTrackingState.create();
return this._tracker;
}
if (type === "site-settings:main") {
this._settings = this._settings || currentSettings();
return this._settings;
2015-03-07 01:37:24 +08:00
}
return customLookup(type);
2015-03-07 01:37:24 +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
}