mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Remove all instances of Ember.computed (#8324)
This commit is contained in:
parent
7e44065bcb
commit
e51efce356
@ -6,9 +6,10 @@ import { setting } from "discourse/lib/computed";
|
|||||||
import AdminDashboard from "admin/models/admin-dashboard";
|
import AdminDashboard from "admin/models/admin-dashboard";
|
||||||
import Report from "admin/models/report";
|
import Report from "admin/models/report";
|
||||||
import PeriodComputationMixin from "admin/mixins/period-computation";
|
import PeriodComputationMixin from "admin/mixins/period-computation";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
|
|
||||||
function staticReport(reportType) {
|
function staticReport(reportType) {
|
||||||
return Ember.computed("reports.[]", function() {
|
return computed("reports.[]", function() {
|
||||||
return makeArray(this.reports).find(report => report.type === reportType);
|
return makeArray(this.reports).find(report => report.type === reportType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@ import discourseComputed from "discourse-common/utils/decorators";
|
|||||||
import AdminUser from "admin/models/admin-user";
|
import AdminUser from "admin/models/admin-user";
|
||||||
import RestModel from "discourse/models/rest";
|
import RestModel from "discourse/models/rest";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
|
|
||||||
const ApiKey = RestModel.extend({
|
const ApiKey = RestModel.extend({
|
||||||
user: Ember.computed("_user", {
|
user: computed("_user", {
|
||||||
get() {
|
get() {
|
||||||
return this._user;
|
return this._user;
|
||||||
},
|
},
|
||||||
|
@ -81,6 +81,7 @@ var define, requirejs;
|
|||||||
isEmpty: Ember.isEmpty
|
isEmpty: Ember.isEmpty
|
||||||
},
|
},
|
||||||
rsvp: {
|
rsvp: {
|
||||||
|
default: Ember.RSVP,
|
||||||
Promise: Ember.RSVP.Promise,
|
Promise: Ember.RSVP.Promise,
|
||||||
hash: Ember.RSVP.hash,
|
hash: Ember.RSVP.hash,
|
||||||
all: Ember.RSVP.all
|
all: Ember.RSVP.all
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
default as discourseComputed,
|
default as discourseComputed,
|
||||||
observes
|
observes
|
||||||
} from "discourse-common/utils/decorators";
|
} from "discourse-common/utils/decorators";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
import FocusEvent from "discourse-common/mixins/focus-event";
|
import FocusEvent from "discourse-common/mixins/focus-event";
|
||||||
|
|
||||||
const _pluginCallbacks = [];
|
const _pluginCallbacks = [];
|
||||||
@ -188,7 +189,7 @@ const Discourse = Ember.Application.extend(FocusEvent, {
|
|||||||
_pluginCallbacks.push({ version, code });
|
_pluginCallbacks.push({ version, code });
|
||||||
},
|
},
|
||||||
|
|
||||||
assetVersion: Ember.computed({
|
assetVersion: computed({
|
||||||
get() {
|
get() {
|
||||||
return this.currentAssetVersion;
|
return this.currentAssetVersion;
|
||||||
},
|
},
|
||||||
|
@ -3,9 +3,10 @@ import { userPath } from "discourse/lib/url";
|
|||||||
import { formatUsername, escapeExpression } from "discourse/lib/utilities";
|
import { formatUsername, escapeExpression } from "discourse/lib/utilities";
|
||||||
import { normalize } from "discourse/components/user-info";
|
import { normalize } from "discourse/components/user-info";
|
||||||
import { renderAvatar } from "discourse/helpers/user-avatar";
|
import { renderAvatar } from "discourse/helpers/user-avatar";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
usersTemplates: Ember.computed("users.[]", function() {
|
usersTemplates: computed("users.[]", function() {
|
||||||
return (this.users || []).map(user => {
|
return (this.users || []).map(user => {
|
||||||
let name = "";
|
let name = "";
|
||||||
if (user.name && normalize(user.username) !== normalize(user.name)) {
|
if (user.name && normalize(user.username) !== normalize(user.name)) {
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
classNames: ["d-date-time-input"],
|
classNames: ["d-date-time-input"],
|
||||||
date: null,
|
date: null,
|
||||||
showTime: true,
|
showTime: true,
|
||||||
|
|
||||||
_hours: Ember.computed("date", function() {
|
_hours: computed("date", function() {
|
||||||
return this.date ? this.date.getHours() : null;
|
return this.date ? this.date.getHours() : null;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
_minutes: Ember.computed("date", function() {
|
_minutes: computed("date", function() {
|
||||||
return this.date ? this.date.getMinutes() : null;
|
return this.date ? this.date.getMinutes() : null;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
import { isEmpty } from "@ember/utils";
|
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 { debounce } from "@ember/runloop";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { inject } from "@ember/controller";
|
import { inject } from "@ember/controller";
|
||||||
@ -158,7 +164,7 @@ export default Controller.extend({
|
|||||||
return "title";
|
return "title";
|
||||||
},
|
},
|
||||||
|
|
||||||
showToolbar: Ember.computed({
|
showToolbar: computed({
|
||||||
get() {
|
get() {
|
||||||
const keyValueStore = getOwner(this).lookup("key-value-store:main");
|
const keyValueStore = getOwner(this).lookup("key-value-store:main");
|
||||||
const storedVal = keyValueStore.get("toolbar-enabled");
|
const storedVal = keyValueStore.get("toolbar-enabled");
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
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 Controller from "@ember/controller";
|
||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
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";
|
import Post from "discourse/models/post";
|
||||||
|
|
||||||
function customTagArray(fieldName) {
|
function customTagArray(fieldName) {
|
||||||
return Ember.computed(fieldName, function() {
|
return computed(fieldName, function() {
|
||||||
var val = this.get(fieldName);
|
var val = this.get(fieldName);
|
||||||
if (!val) {
|
if (!val) {
|
||||||
return val;
|
return val;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import error from "@ember/error";
|
import error from "@ember/error";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
|
|
||||||
let _topicFooterButtons = {};
|
let _topicFooterButtons = {};
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ export function getTopicFooterButtons() {
|
|||||||
.filter(x => x)
|
.filter(x => x)
|
||||||
);
|
);
|
||||||
|
|
||||||
return Ember.computed(...dependentKeys, {
|
return computed(...dependentKeys, {
|
||||||
get() {
|
get() {
|
||||||
const _isFunction = descriptor =>
|
const _isFunction = descriptor =>
|
||||||
descriptor && typeof descriptor === "function";
|
descriptor && typeof descriptor === "function";
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import EmberObjectProxy from "@ember/object/proxy";
|
import EmberObjectProxy from "@ember/object/proxy";
|
||||||
import Mixin from "@ember/object/mixin";
|
import Mixin from "@ember/object/mixin";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
|
|
||||||
/* global BufferedProxy: true */
|
/* global BufferedProxy: true */
|
||||||
export function bufferedProperty(property) {
|
export function bufferedProperty(property) {
|
||||||
const mixin = {
|
const mixin = {
|
||||||
buffered: Ember.computed(property, function() {
|
buffered: computed(property, function() {
|
||||||
return EmberObjectProxy.extend(BufferedProxy).create({
|
return EmberObjectProxy.extend(BufferedProxy).create({
|
||||||
content: this.get(property)
|
content: this.get(property)
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import { get } from "@ember/object";
|
import { get } from "@ember/object";
|
||||||
import { isEmpty } from "@ember/utils";
|
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 EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import RestModel from "discourse/models/rest";
|
import RestModel from "discourse/models/rest";
|
||||||
@ -16,8 +22,8 @@ import Composer from "discourse/models/composer";
|
|||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
|
|
||||||
const Post = RestModel.extend({
|
const Post = RestModel.extend({
|
||||||
// TODO: Remove this once one instantiate all `Post` models via the store.
|
// TODO: Remove this once one instantiate all `Discourse.Post` models via the store.
|
||||||
siteSettings: Ember.computed({
|
siteSettings: computed({
|
||||||
get() {
|
get() {
|
||||||
return Discourse.SiteSettings;
|
return Discourse.SiteSettings;
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { isEmpty } from "@ember/utils";
|
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 EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { url } from "discourse/lib/computed";
|
import { url } from "discourse/lib/computed";
|
||||||
@ -63,7 +63,7 @@ const User = RestModel.extend({
|
|||||||
return UserDraftsStream.create({ user: this });
|
return UserDraftsStream.create({ user: this });
|
||||||
},
|
},
|
||||||
|
|
||||||
staff: Ember.computed("admin", "moderator", {
|
staff: computed("admin", "moderator", {
|
||||||
get() {
|
get() {
|
||||||
return this.admin || this.moderator;
|
return this.admin || this.moderator;
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,7 @@ import { h } from "virtual-dom";
|
|||||||
import { avatarFor } from "discourse/widgets/post";
|
import { avatarFor } from "discourse/widgets/post";
|
||||||
import { userPath } from "discourse/lib/url";
|
import { userPath } from "discourse/lib/url";
|
||||||
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
|
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
|
||||||
|
import computed from "@ember/object/computed";
|
||||||
|
|
||||||
export function actionDescriptionHtml(actionCode, createdAt, username) {
|
export function actionDescriptionHtml(actionCode, createdAt, username) {
|
||||||
const dt = new Date(createdAt);
|
const dt = new Date(createdAt);
|
||||||
@ -22,7 +23,7 @@ export function actionDescriptionHtml(actionCode, createdAt, username) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function actionDescription(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);
|
const ac = this.get(actionCode);
|
||||||
if (ac) {
|
if (ac) {
|
||||||
return actionDescriptionHtml(ac, this.get(createdAt), this.get(username));
|
return actionDescriptionHtml(ac, this.get(createdAt), this.get(username));
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
@class PreloadStore
|
@class PreloadStore
|
||||||
**/
|
**/
|
||||||
|
import { Promise } from "rsvp";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: {},
|
data: {},
|
||||||
|
|
||||||
@ -19,13 +21,13 @@ export default {
|
|||||||
**/
|
**/
|
||||||
getAndRemove(key, finder) {
|
getAndRemove(key, finder) {
|
||||||
if (this.data[key]) {
|
if (this.data[key]) {
|
||||||
var promise = Ember.RSVP.resolve(this.data[key]);
|
var promise = Promise.resolve(this.data[key]);
|
||||||
delete this.data[key];
|
delete this.data[key];
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finder) {
|
if (finder) {
|
||||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var result = finder();
|
var result = finder();
|
||||||
|
|
||||||
// If the finder returns a promise, we support that too
|
// 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) {
|
get(key) {
|
||||||
|
@ -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 Component from "@ember/component";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ export default Component.extend({
|
|||||||
|
|
||||||
value: alias("computedContent.value"),
|
value: alias("computedContent.value"),
|
||||||
|
|
||||||
isLocked: Ember.computed("computedContent.locked", function() {
|
isLocked: computed("computedContent.locked", function() {
|
||||||
return this.getWithDefault("computedContent.locked", false);
|
return this.getWithDefault("computedContent.locked", false);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { run } from "@ember/runloop";
|
import { run } from "@ember/runloop";
|
||||||
import getUrl from "discourse-common/lib/get-url";
|
import getUrl from "discourse-common/lib/get-url";
|
||||||
|
import { Promise } from "rsvp";
|
||||||
import jQuery from "jquery";
|
import jQuery from "jquery";
|
||||||
|
|
||||||
let token;
|
let token;
|
||||||
@ -13,7 +14,7 @@ export function getToken() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ajax(args) {
|
export function ajax(args) {
|
||||||
return new Ember.RSVP.Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
args.headers = { "X-CSRF-Token": getToken() };
|
args.headers = { "X-CSRF-Token": getToken() };
|
||||||
args.success = data => run(null, resolve, data);
|
args.success = data => run(null, resolve, data);
|
||||||
args.error = xhr => run(null, reject, xhr);
|
args.error = xhr => run(null, reject, xhr);
|
||||||
|
@ -2,6 +2,7 @@ import { scheduleOnce } from "@ember/runloop";
|
|||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
/*eslint no-bitwise:0 */
|
/*eslint no-bitwise:0 */
|
||||||
import getUrl from "discourse-common/lib/get-url";
|
import getUrl from "discourse-common/lib/get-url";
|
||||||
|
import { Promise } from "rsvp";
|
||||||
|
|
||||||
export const LOREM = `
|
export const LOREM = `
|
||||||
Lorem ipsum dolor sit amet,
|
Lorem ipsum dolor sit amet,
|
||||||
@ -56,13 +57,13 @@ export function createPreviewComponent(width, height, obj) {
|
|||||||
loadImages() {
|
loadImages() {
|
||||||
const images = this.images();
|
const images = this.images();
|
||||||
if (images) {
|
if (images) {
|
||||||
return Ember.RSVP.Promise.all(
|
return Promise.all(
|
||||||
Object.keys(images).map(id => {
|
Object.keys(images).map(id => {
|
||||||
return loadImage(images[id]).then(img => (this[id] = img));
|
return loadImage(images[id]).then(img => (this[id] = img));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Ember.RSVP.Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|
||||||
reload() {
|
reload() {
|
||||||
@ -270,12 +271,12 @@ export function createPreviewComponent(width, height, obj) {
|
|||||||
|
|
||||||
function loadImage(src) {
|
function loadImage(src) {
|
||||||
if (!src) {
|
if (!src) {
|
||||||
return Ember.RSVP.Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = getUrl(src);
|
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) {
|
export function parseColor(color) {
|
||||||
|
Loading…
Reference in New Issue
Block a user