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

38 lines
1.2 KiB
Plaintext
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 TopicTrackingState from 'discourse/models/topic-tracking-state';
import Resolver from 'discourse/ember/resolver';
2015-03-07 01:37:24 +08:00
export default function() {
const resolver = Resolver.create();
2015-03-07 01:37:24 +08:00
return Store.create({
container: {
lookup(type) {
if (type === "adapter:rest") {
this._restAdapter = this._restAdapter || RestAdapter.create({ container: this });
return (this._restAdapter);
}
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 || Discourse.SiteSettings;
return (this._settings);
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
}
});
}