discourse/test/javascripts/helpers/create-store.js.es6
Kyle Zhao 9b10a78d82 FEATURE: Quick access panels in user menu (#8073)
* Extract QuickAccessPanel from UserNotifications.

* FEATURE: Quick access panels in user menu.

This feature adds quick access panels for bookmarks and personal
messages. It allows uses to browse recent items directly in the user
menu, without being redirected to the full pages.

* REFACTOR: Use QuickAccessItem for messages.

Reusing `DefaultNotificationItem` feels nice but it actually requires a
lot of extra work that is not needed for a quick access item.

Also, `DefaultNotificationItem` shows an incorrect tooptip ("unread
private message"), and it is not trivial to remove / override that.

* Use a plain JS object instead.

An Ember object was required when `DefaultNotificationItem` was used.

* Prefix instead suffix `_` for private helpers.

* Set to null instead of deleting object keys.

JavaScript engines can optimize object property access based on the
object’s shape. https://mathiasbynens.be/notes/shapes-ics

* Change trivial try/catch to one-liners.

* Return the promise in case needs to be waited on.

* Refactor showAll to a link with href

* Store `emptyStatePlaceholderItemText` in state.

* Store items in Session singleton instead.

We can drop `staleItems` (and `findStaleItems`) altogether. Because
`(old) items === staleItems` when switching back to a quick access
panel.

* Add `limit` parameter to the `user_actions` API.

* Explicitly import Session instead.
2019-09-09 11:03:57 -04:00

49 lines
1.5 KiB
JavaScript

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";
export default function() {
const resolver = buildResolver("discourse").create();
return Store.create({
register: {
lookup(type) {
if (type === "adapter:rest") {
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 || Discourse.SiteSettings;
return this._settings;
}
},
lookupFactory(type) {
const split = type.split(":");
return resolver.customResolve({
type: split[0],
fullNameWithoutType: split[1]
});
}
}
});
}