REFACTOR: Ember.makeArray was removed from the public API

This commit is contained in:
Robin Ward 2019-10-31 13:55:01 -04:00
parent 90f934a660
commit 89f602f66b
16 changed files with 44 additions and 22 deletions

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { debounce } from "@ember/runloop";
import { schedule } from "@ember/runloop";
import Component from "@ember/component";
@ -49,10 +50,10 @@ export default Component.extend({
if (!chartCanvas) return;
const context = chartCanvas.getContext("2d");
const chartData = Ember.makeArray(
const chartData = makeArray(
model.get("chartData") || model.get("data")
);
const prevChartData = Ember.makeArray(
const prevChartData = makeArray(
model.get("prevChartData") || model.get("prev_data")
);

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { debounce } from "@ember/runloop";
import { schedule } from "@ember/runloop";
import Component from "@ember/component";
@ -52,7 +53,7 @@ export default Component.extend({
const context = chartCanvas.getContext("2d");
const chartData = Ember.makeArray(
const chartData = makeArray(
model.get("chartData") || model.get("data")
);

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { alias } from "@ember/object/computed";
import Component from "@ember/component";
import computed from "ember-addons/ember-computed-decorators";
@ -91,7 +92,7 @@ export default Component.extend({
@computed("sortLabel", "sortDirection", "model.data.[]")
sortedData(sortLabel, sortDirection, data) {
data = Ember.makeArray(data);
data = makeArray(data);
if (sortLabel) {
const compare = (label, direction) => {

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { alias, or, and, reads, equal, notEmpty } from "@ember/object/computed";
import EmberObject from "@ember/object";
import { next } from "@ember/runloop";
@ -108,7 +109,7 @@ export default Component.extend({
displayedModes(currentMode, reportModes, forcedModes) {
const modes = forcedModes ? forcedModes.split(",") : reportModes;
return Ember.makeArray(modes).map(mode => {
return makeArray(modes).map(mode => {
const base = `btn-default mode-btn ${mode}`;
const cssClass = currentMode === mode ? `${base} is-current` : base;

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { empty, alias } from "@ember/object/computed";
import Component from "@ember/component";
import { on } from "ember-addons/ember-computed-decorators";
@ -31,7 +32,7 @@ export default Component.extend({
@computed("choices.[]", "collection.[]")
filteredChoices(choices, collection) {
return Ember.makeArray(choices).filter(i => collection.indexOf(i) < 0);
return makeArray(choices).filter(i => collection.indexOf(i) < 0);
},
keyDown(event) {

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { empty, notEmpty, match } from "@ember/object/computed";
import Controller from "@ember/controller";
import { default as computed } from "ember-addons/ember-computed-decorators";
@ -126,8 +127,8 @@ export default Controller.extend({
});
this.get("parentController.model.content").forEach(theme => {
const children = Ember.makeArray(theme.get("childThemes"));
const rawChildren = Ember.makeArray(theme.get("child_themes"));
const children = makeArray(theme.get("childThemes"));
const rawChildren = makeArray(theme.get("child_themes"));
const index = children ? children.indexOf(model) : -1;
if (index > -1) {
children.splice(index, 1);

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { inject } from "@ember/controller";
import Controller from "@ember/controller";
import { setting } from "discourse/lib/computed";
@ -8,7 +9,7 @@ import PeriodComputationMixin from "admin/mixins/period-computation";
function staticReport(reportType) {
return Ember.computed("reports.[]", function() {
return Ember.makeArray(this.reports).find(
return makeArray(this.reports).find(
report => report.type === reportType
);
});
@ -95,7 +96,7 @@ export default Controller.extend(PeriodComputationMixin, {
this.setProperties({
dashboardFetchedAt: new Date(),
model: adminDashboardModel,
reports: Ember.makeArray(adminDashboardModel.reports).map(x =>
reports: makeArray(adminDashboardModel.reports).map(x =>
Report.create(x)
)
});

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { isEmpty } from "@ember/utils";
import EmberObject from "@ember/object";
import { escapeExpression } from "discourse/lib/utilities";
@ -137,7 +138,7 @@ const Report = Discourse.Model.extend({
@computed("data", "currentTotal")
currentAverage(data, total) {
return Ember.makeArray(data).length === 0
return makeArray(data).length === 0
? 0
: parseFloat((total / parseFloat(data.length)).toFixed(1));
},

View File

@ -3,6 +3,13 @@ import toMarkdown from "discourse/lib/to-markdown";
const homepageSelector = "meta[name=discourse_current_homepage]";
export function makeArray(obj) {
if (obj === null || obj === undefined) {
return [];
}
return Array.isArray(obj) ? obj : [obj];
}
export function translateSize(size) {
switch (size) {
case "tiny":

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { createWidget } from "discourse/widgets/widget";
import { h } from "virtual-dom";
import { avatarFor, avatarImg } from "discourse/widgets/post";
@ -146,7 +147,7 @@ export default createWidget("private-message-map", {
if (
!this.state.isEditing &&
this.site.mobileView &&
Ember.makeArray(participants[0]).length > 4
makeArray(participants[0]).length > 4
) {
hideNamesClass = ".hide-names";
}

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import MultiSelectComponent from "select-kit/components/multi-select";
import Category from "discourse/models/category";
@ -28,7 +29,7 @@ export default MultiSelectComponent.extend({
},
computeValues() {
return Ember.makeArray(this.categories).map(c => c.id);
return makeArray(this.categories).map(c => c.id);
},
mutateValues(values) {
@ -43,7 +44,7 @@ export default MultiSelectComponent.extend({
},
computeContent() {
const blacklist = Ember.makeArray(this.blacklist);
const blacklist = makeArray(this.blacklist);
return Category.list().filter(category => {
return (
this.categories.includes(category) || !blacklist.includes(category)

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import Category from "discourse/models/category";
import ComboBox from "select-kit/components/combo-box";
import TagsMixin from "select-kit/mixins/tags";
@ -5,7 +6,7 @@ import { default as computed } from "ember-addons/ember-computed-decorators";
import renderTag from "discourse/lib/render-tag";
import { escapeExpression } from "discourse/lib/utilities";
import { iconHTML } from "discourse-common/lib/icon-library";
const { get, isEmpty, run, makeArray } = Ember;
const { get, isEmpty, run } = Ember;
export default ComboBox.extend(TagsMixin, {
allowContentReplacement: true,
@ -226,7 +227,7 @@ export default ComboBox.extend(TagsMixin, {
},
destroyTags(tags) {
tags = Ember.makeArray(tags).map(c => get(c, "value"));
tags = makeArray(tags).map(c => get(c, "value"));
// work around usage with buffered proxy
// it does not listen on array changes, similar hack already on select

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { on } from "ember-addons/ember-computed-decorators";
import computed from "ember-addons/ember-computed-decorators";
import SelectKitHeaderComponent from "select-kit/components/select-kit/select-kit-header";
@ -39,14 +40,14 @@ export default SelectKitHeaderComponent.extend({
@computed("computedContent.selection.[]")
names(selection) {
return Ember.makeArray(selection)
return makeArray(selection)
.map(s => s.name)
.join(",");
},
@computed("computedContent.selection.[]")
values(selection) {
return Ember.makeArray(selection)
return makeArray(selection)
.map(s => s.value)
.join(",");
}

View File

@ -2,7 +2,8 @@ import MultiSelectComponent from "select-kit/components/multi-select";
import TagsMixin from "select-kit/mixins/tags";
import renderTag from "discourse/lib/render-tag";
import computed from "ember-addons/ember-computed-decorators";
const { get, run, makeArray } = Ember;
import { makeArray } from "discourse/lib/utilities";
const { get, run } = Ember;
export default MultiSelectComponent.extend(TagsMixin, {
pluginApiIdentifiers: ["tag-chooser"],

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import ComboBoxComponent from "select-kit/components/combo-box";
import DiscourseURL from "discourse/lib/url";
import TagsMixin from "select-kit/mixins/tags";
@ -123,7 +124,7 @@ export default ComboBoxComponent.extend(TagsMixin, {
if (this.siteSettings.tags_sort_alphabetically && topTags) {
return shortcuts.concat(topTags.sort());
} else {
return shortcuts.concat(Ember.makeArray(topTags));
return shortcuts.concat(makeArray(topTags));
}
},

View File

@ -1,3 +1,4 @@
import { makeArray } from "discourse/lib/utilities";
import { isEmpty } from "@ember/utils";
import { throttle } from "@ember/runloop";
import { schedule } from "@ember/runloop";
@ -293,7 +294,7 @@ export default Mixin.create({
if (!this.highlightedSelection.length) {
// try to highlight the last non locked item from the current selection
Ember.makeArray(this.selection)
makeArray(this.selection)
.slice()
.reverse()
.some(selection => {
@ -311,7 +312,7 @@ export default Mixin.create({
},
didPressSelectAll() {
this.highlightSelection(Ember.makeArray(this.selection));
this.highlightSelection(makeArray(this.selection));
},
didClickOutside(event) {