DEV: Remove all instances of Ember.computed (#8324)

This commit is contained in:
Mark VanLandingham 2019-11-08 12:28:11 -06:00 committed by GitHub
parent 7e44065bcb
commit e51efce356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 60 additions and 28 deletions

View File

@ -6,9 +6,10 @@ import { setting } from "discourse/lib/computed";
import AdminDashboard from "admin/models/admin-dashboard";
import Report from "admin/models/report";
import PeriodComputationMixin from "admin/mixins/period-computation";
import computed from "@ember/object/computed";
function staticReport(reportType) {
return Ember.computed("reports.[]", function() {
return computed("reports.[]", function() {
return makeArray(this.reports).find(report => report.type === reportType);
});
}

View File

@ -2,9 +2,10 @@ import discourseComputed from "discourse-common/utils/decorators";
import AdminUser from "admin/models/admin-user";
import RestModel from "discourse/models/rest";
import { ajax } from "discourse/lib/ajax";
import computed from "@ember/object/computed";
const ApiKey = RestModel.extend({
user: Ember.computed("_user", {
user: computed("_user", {
get() {
return this._user;
},

View File

@ -81,6 +81,7 @@ var define, requirejs;
isEmpty: Ember.isEmpty
},
rsvp: {
default: Ember.RSVP,
Promise: Ember.RSVP.Promise,
hash: Ember.RSVP.hash,
all: Ember.RSVP.all

View File

@ -4,6 +4,7 @@ import {
default as discourseComputed,
observes
} from "discourse-common/utils/decorators";
import computed from "@ember/object/computed";
import FocusEvent from "discourse-common/mixins/focus-event";
const _pluginCallbacks = [];
@ -188,7 +189,7 @@ const Discourse = Ember.Application.extend(FocusEvent, {
_pluginCallbacks.push({ version, code });
},
assetVersion: Ember.computed({
assetVersion: computed({
get() {
return this.currentAssetVersion;
},

View File

@ -3,9 +3,10 @@ import { userPath } from "discourse/lib/url";
import { formatUsername, escapeExpression } from "discourse/lib/utilities";
import { normalize } from "discourse/components/user-info";
import { renderAvatar } from "discourse/helpers/user-avatar";
import computed from "@ember/object/computed";
export default Component.extend({
usersTemplates: Ember.computed("users.[]", function() {
usersTemplates: computed("users.[]", function() {
return (this.users || []).map(user => {
let name = "";
if (user.name && normalize(user.username) !== normalize(user.name)) {

View File

@ -1,15 +1,16 @@
import Component from "@ember/component";
import computed from "@ember/object/computed";
export default Component.extend({
classNames: ["d-date-time-input"],
date: null,
showTime: true,
_hours: Ember.computed("date", function() {
_hours: computed("date", function() {
return this.date ? this.date.getHours() : null;
}),
_minutes: Ember.computed("date", function() {
_minutes: computed("date", function() {
return this.date ? this.date.getMinutes() : null;
}),

View File

@ -1,5 +1,11 @@
import { isEmpty } from "@ember/utils";
import { and, or, alias, reads } from "@ember/object/computed";
import {
default as computed,
and,
or,
alias,
reads
} from "@ember/object/computed";
import { debounce } from "@ember/runloop";
import { inject as service } from "@ember/service";
import { inject } from "@ember/controller";
@ -158,7 +164,7 @@ export default Controller.extend({
return "title";
},
showToolbar: Ember.computed({
showToolbar: computed({
get() {
const keyValueStore = getOwner(this).lookup("key-value-store:main");
const storedVal = keyValueStore.get("toolbar-enabled");

View File

@ -1,5 +1,12 @@
import discourseComputed from "discourse-common/utils/decorators";
import { alias, gt, not, or, equal } from "@ember/object/computed";
import {
default as computed,
alias,
gt,
not,
or,
equal
} from "@ember/object/computed";
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
@ -10,7 +17,7 @@ import { iconHTML } from "discourse-common/lib/icon-library";
import Post from "discourse/models/post";
function customTagArray(fieldName) {
return Ember.computed(fieldName, function() {
return computed(fieldName, function() {
var val = this.get(fieldName);
if (!val) {
return val;

View File

@ -1,4 +1,5 @@
import error from "@ember/error";
import computed from "@ember/object/computed";
let _topicFooterButtons = {};
@ -70,7 +71,7 @@ export function getTopicFooterButtons() {
.filter(x => x)
);
return Ember.computed(...dependentKeys, {
return computed(...dependentKeys, {
get() {
const _isFunction = descriptor =>
descriptor && typeof descriptor === "function";

View File

@ -1,10 +1,11 @@
import EmberObjectProxy from "@ember/object/proxy";
import Mixin from "@ember/object/mixin";
import computed from "@ember/object/computed";
/* global BufferedProxy: true */
export function bufferedProperty(property) {
const mixin = {
buffered: Ember.computed(property, function() {
buffered: computed(property, function() {
return EmberObjectProxy.extend(BufferedProxy).create({
content: this.get(property)
});

View File

@ -1,7 +1,13 @@
import discourseComputed from "discourse-common/utils/decorators";
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { equal, and, or, not } from "@ember/object/computed";
import {
default as computed,
equal,
and,
or,
not
} from "@ember/object/computed";
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import RestModel from "discourse/models/rest";
@ -16,8 +22,8 @@ import Composer from "discourse/models/composer";
import { Promise } from "rsvp";
const Post = RestModel.extend({
// TODO: Remove this once one instantiate all `Post` models via the store.
siteSettings: Ember.computed({
// TODO: Remove this once one instantiate all `Discourse.Post` models via the store.
siteSettings: computed({
get() {
return Discourse.SiteSettings;
},

View File

@ -1,5 +1,5 @@
import { isEmpty } from "@ember/utils";
import { gt, equal, or } from "@ember/object/computed";
import { default as computed, gt, equal, or } from "@ember/object/computed";
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { url } from "discourse/lib/computed";
@ -63,7 +63,7 @@ const User = RestModel.extend({
return UserDraftsStream.create({ user: this });
},
staff: Ember.computed("admin", "moderator", {
staff: computed("admin", "moderator", {
get() {
return this.admin || this.moderator;
},

View File

@ -5,6 +5,7 @@ import { h } from "virtual-dom";
import { avatarFor } from "discourse/widgets/post";
import { userPath } from "discourse/lib/url";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
import computed from "@ember/object/computed";
export function actionDescriptionHtml(actionCode, createdAt, username) {
const dt = new Date(createdAt);
@ -22,7 +23,7 @@ export function actionDescriptionHtml(actionCode, createdAt, username) {
}
export function actionDescription(actionCode, createdAt, username) {
return Ember.computed(actionCode, createdAt, function() {
return computed(actionCode, createdAt, function() {
const ac = this.get(actionCode);
if (ac) {
return actionDescriptionHtml(ac, this.get(createdAt), this.get(username));

View File

@ -4,6 +4,8 @@
@class PreloadStore
**/
import { Promise } from "rsvp";
export default {
data: {},
@ -19,13 +21,13 @@ export default {
**/
getAndRemove(key, finder) {
if (this.data[key]) {
var promise = Ember.RSVP.resolve(this.data[key]);
var promise = Promise.resolve(this.data[key]);
delete this.data[key];
return promise;
}
if (finder) {
return new Ember.RSVP.Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
var result = finder();
// If the finder returns a promise, we support that too
@ -39,7 +41,7 @@ export default {
});
}
return Ember.RSVP.resolve(null);
return Promise.resolve(null);
},
get(key) {

View File

@ -1,4 +1,4 @@
import { or, alias } from "@ember/object/computed";
import { default as computed, or, alias } from "@ember/object/computed";
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
@ -38,7 +38,7 @@ export default Component.extend({
value: alias("computedContent.value"),
isLocked: Ember.computed("computedContent.locked", function() {
isLocked: computed("computedContent.locked", function() {
return this.getWithDefault("computedContent.locked", false);
}),

View File

@ -1,5 +1,6 @@
import { run } from "@ember/runloop";
import getUrl from "discourse-common/lib/get-url";
import { Promise } from "rsvp";
import jQuery from "jquery";
let token;
@ -13,7 +14,7 @@ export function getToken() {
}
export function ajax(args) {
return new Ember.RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
args.headers = { "X-CSRF-Token": getToken() };
args.success = data => run(null, resolve, data);
args.error = xhr => run(null, reject, xhr);

View File

@ -2,6 +2,7 @@ import { scheduleOnce } from "@ember/runloop";
import Component from "@ember/component";
/*eslint no-bitwise:0 */
import getUrl from "discourse-common/lib/get-url";
import { Promise } from "rsvp";
export const LOREM = `
Lorem ipsum dolor sit amet,
@ -56,13 +57,13 @@ export function createPreviewComponent(width, height, obj) {
loadImages() {
const images = this.images();
if (images) {
return Ember.RSVP.Promise.all(
return Promise.all(
Object.keys(images).map(id => {
return loadImage(images[id]).then(img => (this[id] = img));
})
);
}
return Ember.RSVP.Promise.resolve();
return Promise.resolve();
},
reload() {
@ -270,12 +271,12 @@ export function createPreviewComponent(width, height, obj) {
function loadImage(src) {
if (!src) {
return Ember.RSVP.Promise.resolve();
return Promise.resolve();
}
const img = new Image();
img.src = getUrl(src);
return new Ember.RSVP.Promise(resolve => (img.onload = () => resolve(img)));
return new Promise(resolve => (img.onload = () => resolve(img)));
}
export function parseColor(color) {