mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Move computed to discourseComputed (#8312)
This commit is contained in:

committed by
GitHub

parent
d74546f50e
commit
6275c05c0d
@ -1,7 +1,8 @@
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import EmberObject from "@ember/object";
|
||||
import Component from "@ember/component";
|
||||
const { get, isNone, run, isEmpty, makeArray } = Ember;
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
|
||||
import UtilsMixin from "select-kit/mixins/utils";
|
||||
import DomHelpersMixin from "select-kit/mixins/dom-helpers";
|
||||
import EventsMixin from "select-kit/mixins/events";
|
||||
@ -223,7 +224,7 @@ export default Component.extend(
|
||||
return this.computeContentItem(contentItem, options);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"isAsync",
|
||||
"isLoading",
|
||||
"filteredAsyncComputedContent.[]",
|
||||
@ -250,28 +251,28 @@ export default Component.extend(
|
||||
return !this.hasReachedMaximum;
|
||||
},
|
||||
|
||||
@computed("maximum", "selection.[]")
|
||||
@discourseComputed("maximum", "selection.[]")
|
||||
hasReachedMaximum(maximum, selection) {
|
||||
if (!maximum) return false;
|
||||
selection = makeArray(selection);
|
||||
return selection.length >= maximum;
|
||||
},
|
||||
|
||||
@computed("minimum", "selection.[]")
|
||||
@discourseComputed("minimum", "selection.[]")
|
||||
hasReachedMinimum(minimum, selection) {
|
||||
if (!minimum) return true;
|
||||
selection = makeArray(selection);
|
||||
return selection.length >= minimum;
|
||||
},
|
||||
|
||||
@computed("shouldFilter", "allowAny")
|
||||
@discourseComputed("shouldFilter", "allowAny")
|
||||
shouldDisplayFilter(shouldFilter, allowAny) {
|
||||
if (shouldFilter) return true;
|
||||
if (allowAny) return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
@computed("filter", "collectionComputedContent.[]", "isLoading")
|
||||
@discourseComputed("filter", "collectionComputedContent.[]", "isLoading")
|
||||
noContentRow(filter, collectionComputedContent, isLoading) {
|
||||
if (
|
||||
filter.length > 0 &&
|
||||
@ -282,7 +283,7 @@ export default Component.extend(
|
||||
}
|
||||
},
|
||||
|
||||
@computed("hasReachedMaximum", "hasReachedMinimum", "isExpanded")
|
||||
@discourseComputed("hasReachedMaximum", "hasReachedMinimum", "isExpanded")
|
||||
validationMessage(hasReachedMaximum, hasReachedMinimum) {
|
||||
if (hasReachedMaximum && this.maximum) {
|
||||
const key = this.maximumLabel || "select_kit.max_content_reached";
|
||||
@ -295,14 +296,19 @@ export default Component.extend(
|
||||
}
|
||||
},
|
||||
|
||||
@computed("allowAny")
|
||||
@discourseComputed("allowAny")
|
||||
filterPlaceholder(allowAny) {
|
||||
return allowAny
|
||||
? "select_kit.filter_placeholder_with_any"
|
||||
: "select_kit.filter_placeholder";
|
||||
},
|
||||
|
||||
@computed("filter", "filterable", "autoFilterable", "renderedFilterOnce")
|
||||
@discourseComputed(
|
||||
"filter",
|
||||
"filterable",
|
||||
"autoFilterable",
|
||||
"renderedFilterOnce"
|
||||
)
|
||||
shouldFilter(filter, filterable, autoFilterable, renderedFilterOnce) {
|
||||
if (renderedFilterOnce && filterable) return true;
|
||||
if (filterable) return true;
|
||||
@ -310,7 +316,7 @@ export default Component.extend(
|
||||
return false;
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"computedValue",
|
||||
"filter",
|
||||
"collectionComputedContent.[]",
|
||||
@ -331,7 +337,7 @@ export default Component.extend(
|
||||
return false;
|
||||
},
|
||||
|
||||
@computed("filter", "shouldDisplayCreateRow")
|
||||
@discourseComputed("filter", "shouldDisplayCreateRow")
|
||||
createRowComputedContent(filter, shouldDisplayCreateRow) {
|
||||
if (shouldDisplayCreateRow) {
|
||||
let content = this.createContentFromInput(filter);
|
||||
@ -343,17 +349,17 @@ export default Component.extend(
|
||||
}
|
||||
},
|
||||
|
||||
@computed
|
||||
@discourseComputed
|
||||
templateForRow() {
|
||||
return () => null;
|
||||
},
|
||||
|
||||
@computed
|
||||
@discourseComputed
|
||||
templateForNoneRow() {
|
||||
return () => null;
|
||||
},
|
||||
|
||||
@computed("filter")
|
||||
@discourseComputed("filter")
|
||||
templateForCreateRow() {
|
||||
return rowComponent => {
|
||||
return I18n.t("select_kit.create", {
|
||||
@ -362,7 +368,7 @@ export default Component.extend(
|
||||
};
|
||||
},
|
||||
|
||||
@computed("none")
|
||||
@discourseComputed("none")
|
||||
noneRowComputedContent(none) {
|
||||
if (isNone(none)) return null;
|
||||
|
||||
@ -427,7 +433,12 @@ export default Component.extend(
|
||||
this._boundaryActionHandler("onStopLoading");
|
||||
},
|
||||
|
||||
@computed("selection.[]", "isExpanded", "filter", "highlightedSelection.[]")
|
||||
@discourseComputed(
|
||||
"selection.[]",
|
||||
"isExpanded",
|
||||
"filter",
|
||||
"highlightedSelection.[]"
|
||||
)
|
||||
collectionHeaderComputedContent() {
|
||||
return applyCollectionHeaderCallbacks(
|
||||
this.pluginApiIdentifiers,
|
||||
@ -436,7 +447,7 @@ export default Component.extend(
|
||||
);
|
||||
},
|
||||
|
||||
@computed("selection.[]", "isExpanded", "headerIcon")
|
||||
@discourseComputed("selection.[]", "isExpanded", "headerIcon")
|
||||
headerComputedContent() {
|
||||
return applyHeaderContentPluginApiCallbacks(
|
||||
this.pluginApiIdentifiers,
|
||||
|
Reference in New Issue
Block a user