mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: more efficient topic-footer-button-api (#7535)
This commit is contained in:
parent
750c125707
commit
717aa764b6
@ -1,6 +1,15 @@
|
||||
let _topicFooterButtons = [];
|
||||
let _topicFooterButtons = {};
|
||||
|
||||
export function registerTopicFooterButton(button) {
|
||||
if (!button.id) {
|
||||
Ember.error(`Attempted to register a topic button: ${button} with no id.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_topicFooterButtons[button.id]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultButton = {
|
||||
// id of the button, required
|
||||
id: null,
|
||||
@ -38,11 +47,6 @@ export function registerTopicFooterButton(button) {
|
||||
|
||||
const normalizedButton = Object.assign(defaultButton, button);
|
||||
|
||||
if (!normalizedButton.id) {
|
||||
Ember.error(`Attempted to register a topic button: ${button} with no id.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!normalizedButton.icon &&
|
||||
!normalizedButton.title &&
|
||||
@ -56,14 +60,14 @@ export function registerTopicFooterButton(button) {
|
||||
return;
|
||||
}
|
||||
|
||||
_topicFooterButtons.push(normalizedButton);
|
||||
|
||||
_topicFooterButtons = _topicFooterButtons.uniqBy("id");
|
||||
_topicFooterButtons[normalizedButton.id] = normalizedButton;
|
||||
}
|
||||
|
||||
export function getTopicFooterButtons() {
|
||||
const dependentKeys = [].concat(
|
||||
..._topicFooterButtons.map(tfb => tfb.dependentKeys).filter(x => x)
|
||||
...Object.values(_topicFooterButtons)
|
||||
.map(tfb => tfb.dependentKeys)
|
||||
.filter(x => x)
|
||||
);
|
||||
|
||||
const computedFunc = Ember.computed({
|
||||
@ -81,7 +85,7 @@ export function getTopicFooterButtons() {
|
||||
return field;
|
||||
};
|
||||
|
||||
return _topicFooterButtons
|
||||
return Object.values(_topicFooterButtons)
|
||||
.filter(button => _compute(button, "displayed"))
|
||||
.map(button => {
|
||||
const computedButon = {};
|
||||
|
Loading…
Reference in New Issue
Block a user