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) {
|
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 = {
|
const defaultButton = {
|
||||||
// id of the button, required
|
// id of the button, required
|
||||||
id: null,
|
id: null,
|
||||||
@ -38,11 +47,6 @@ export function registerTopicFooterButton(button) {
|
|||||||
|
|
||||||
const normalizedButton = Object.assign(defaultButton, button);
|
const normalizedButton = Object.assign(defaultButton, button);
|
||||||
|
|
||||||
if (!normalizedButton.id) {
|
|
||||||
Ember.error(`Attempted to register a topic button: ${button} with no id.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!normalizedButton.icon &&
|
!normalizedButton.icon &&
|
||||||
!normalizedButton.title &&
|
!normalizedButton.title &&
|
||||||
@ -56,14 +60,14 @@ export function registerTopicFooterButton(button) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_topicFooterButtons.push(normalizedButton);
|
_topicFooterButtons[normalizedButton.id] = normalizedButton;
|
||||||
|
|
||||||
_topicFooterButtons = _topicFooterButtons.uniqBy("id");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTopicFooterButtons() {
|
export function getTopicFooterButtons() {
|
||||||
const dependentKeys = [].concat(
|
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({
|
const computedFunc = Ember.computed({
|
||||||
@ -81,7 +85,7 @@ export function getTopicFooterButtons() {
|
|||||||
return field;
|
return field;
|
||||||
};
|
};
|
||||||
|
|
||||||
return _topicFooterButtons
|
return Object.values(_topicFooterButtons)
|
||||||
.filter(button => _compute(button, "displayed"))
|
.filter(button => _compute(button, "displayed"))
|
||||||
.map(button => {
|
.map(button => {
|
||||||
const computedButon = {};
|
const computedButon = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user