REFACTOR: Remove `Ember.get`

This commit is contained in:
Robin Ward 2019-10-31 16:28:10 -04:00
parent 89f602f66b
commit 640a05c4ee
31 changed files with 84 additions and 56 deletions

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { or, gt } from "@ember/object/computed";
import RestModel from "discourse/models/rest";
@ -243,7 +244,7 @@ const Theme = RestModel.extend({
@computed("childThemes.[]")
child_theme_ids(childThemes) {
if (childThemes) {
return childThemes.map(theme => Ember.get(theme, "id"));
return childThemes.map(theme => get(theme, "id"));
}
},

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import Route from "@ember/routing/route";
import { ajax } from "discourse/lib/ajax";
import Badge from "discourse/models/badge";
@ -5,7 +6,7 @@ import showModal from "discourse/lib/show-modal";
export default Route.extend({
serialize(m) {
return { badge_id: Ember.get(m, "id") || "new" };
return { badge_id: get(m, "id") || "new" };
},
model(params) {

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import DiscourseRoute from "discourse/routes/discourse";
import AdminUser from "admin/models/admin-user";
@ -10,7 +11,7 @@ export default DiscourseRoute.extend({
},
model(params) {
return AdminUser.find(Ember.get(params, "user_id"));
return AdminUser.find(get(params, "user_id"));
},
renderTemplate() {

View File

@ -1,10 +1,11 @@
import { get } from "@ember/object";
import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({
model(params) {
return this.store.findAll(
"web-hook-event",
Ember.get(params, "web_hook_id")
get(params, "web_hook_id")
);
},

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import DiscourseRoute from "discourse/routes/discourse";
@ -10,7 +11,7 @@ export default DiscourseRoute.extend({
if (params.web_hook_id === "new") {
return this.store.createRecord("web-hook");
}
return this.store.find("web-hook", Ember.get(params, "web_hook_id"));
return this.store.find("web-hook", get(params, "web_hook_id"));
},
setupController(controller, model) {

View File

@ -1,4 +1,4 @@
import { get } from "discourse-common/lib/raw-handlebars";
import { rawGet } from "discourse-common/lib/raw-handlebars";
export function htmlHelper(fn) {
return Ember.Helper.helper(function(...args) {
@ -39,7 +39,7 @@ function resolveParams(ctx, options) {
) {
params[k] = hash[k];
} else if (type === "ID" || type === "PathExpression") {
params[k] = get(ctx, hash[k], options);
params[k] = rawGet(ctx, hash[k], options);
}
});
} else {
@ -59,7 +59,7 @@ export function registerUnbound(name, fn) {
options.types &&
(options.types[i] === "ID" || options.types[i] === "PathExpression")
) {
properties[i] = get(this, properties[i], options);
properties[i] = rawGet(this, properties[i], options);
}
}

View File

@ -1,3 +1,5 @@
import { get } from "@ember/object";
// This is a mechanism for quickly rendering templates which is Ember aware
// templates are highly compatible with Ember so you don't need to worry about calling "get"
// and computed properties function, additionally it uses stringParams like Ember does
@ -24,7 +26,7 @@ RawHandlebars.helpers["get"] = function(context, options) {
context = context.slice(context.indexOf(".") + 1);
}
return val === undefined ? Ember.get(firstContext, context) : val;
return val === undefined ? get(firstContext, context) : val;
};
// adds compatability so this works with stringParams
@ -45,7 +47,7 @@ RawHandlebars.registerHelper("each", function(
contextName,
options
) {
var list = Ember.get(this, contextName);
var list = get(this, contextName);
var output = [];
var innerContext = objectCreate(this);
for (var i = 0; i < list.length; i++) {
@ -178,7 +180,7 @@ RawHandlebars.get = function(ctx, property, options) {
? view.getStream(property).value()
: view.getAttr(property);
} else {
return Ember.get(ctx, property);
return get(ctx, property);
}
};
@ -194,7 +196,7 @@ export function compile() {
return RawHandlebars.compile.apply(this, arguments);
}
export function get() {
export function rawGet() {
return RawHandlebars.get.apply(this, arguments);
}

View File

@ -11,7 +11,10 @@ var define, requirejs;
default: Ember.Controller,
inject: Ember.inject.controller
},
"@ember/object": { default: Ember.Object },
"@ember/object": {
default: Ember.Object,
get: Ember.get
},
"@ember/object/computed": {
default: Ember.computed,
alias: Ember.computed.alias,

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { next } from "@ember/runloop";
import Component from "@ember/component";
@ -57,7 +58,7 @@ export default Component.extend({
actions: {
chooseMessage(message) {
const messageId = Ember.get(message, "id");
const messageId = get(message, "id");
this.set("selectedTopicId", messageId);
next(() => $(`#choose-message-${messageId}`).prop("checked", "true"));
return false;

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import Component from "@ember/component";
import computed from "ember-addons/ember-computed-decorators";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
@ -35,7 +36,7 @@ export default Component.extend({
if (
category &&
Ember.get(category, "id") ===
get(category, "id") ===
Discourse.Site.currentProp("uncategorized_category_id")
) {
category = null;

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { htmlHelper } from "discourse-common/lib/helpers";
import { avatarImg } from "discourse/lib/utilities";
@ -8,6 +9,6 @@ export default htmlHelper((user, size) => {
return "<div class='avatar-placeholder'></div>";
}
const avatarTemplate = Ember.get(user, "avatar_template");
const avatarTemplate = get(user, "avatar_template");
return avatarImg(addExtraUserClasses(user, { size, avatarTemplate }));
});

View File

@ -1,10 +1,9 @@
import { get } from "@ember/object";
import { registerUnbound } from "discourse-common/lib/helpers";
import { isRTL } from "discourse/lib/text-direction";
import { iconHTML } from "discourse-common/lib/icon-library";
var get = Ember.get,
escapeExpression = Handlebars.Utils.escapeExpression;
let escapeExpression = Handlebars.Utils.escapeExpression;
let _renderer = defaultCategoryLinkRenderer;
export function replaceCategoryLinkRenderer(fn) {
@ -32,7 +31,7 @@ export function categoryBadgeHTML(category, opts) {
if (
!category ||
(!opts.allowUncategorized &&
Ember.get(category, "id") ===
get(category, "id") ===
Discourse.Site.currentProp("uncategorized_category_id") &&
Discourse.SiteSettings.suppress_uncategorized_badge)
)

View File

@ -1,10 +1,11 @@
import { get } from "@ember/object";
export function formatCurrency([reviewable, fieldId]) {
// The field `category_id` corresponds to `category`
if (fieldId === "category_id") {
fieldId = "category.id";
}
let value = Ember.get(reviewable, fieldId);
let value = get(reviewable, fieldId);
// If it's an array, say tags, make a copy so we aren't mutating the original
if (Array.isArray(value)) {

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { registerUnbound } from "discourse-common/lib/helpers";
import { avatarImg, formatUsername } from "discourse/lib/utilities";
@ -30,9 +31,9 @@ function renderAvatar(user, options) {
options = options || {};
if (user) {
const name = Ember.get(user, options.namePath || "name");
const username = Ember.get(user, options.usernamePath || "username");
const avatarTemplate = Ember.get(
const name = get(user, options.namePath || "name");
const username = get(user, options.usernamePath || "username");
const avatarTemplate = get(
user,
options.avatarTemplatePath || "avatar_template"
);
@ -46,11 +47,11 @@ function renderAvatar(user, options) {
let title = options.title;
if (!title && !options.ignoreTitle) {
// first try to get a title
title = Ember.get(user, "title");
title = get(user, "title");
// if there was no title provided
if (!title) {
// try to retrieve a description
const description = Ember.get(user, "description");
const description = get(user, "description");
// if a description has been provided
if (description && description.length > 0) {
// preprend the username before the description
@ -61,7 +62,7 @@ function renderAvatar(user, options) {
return avatarImg({
size: options.imageSize,
extraClasses: Ember.get(user, "extras") || options.extraClasses,
extraClasses: get(user, "extras") || options.extraClasses,
title: title || displayName,
avatarTemplate: avatarTemplate
});

View File

@ -463,7 +463,7 @@ class PluginApi {
```javascript
api.customUserAvatarClasses(user => {
if (Ember.get(user, 'primary_group_name') === 'managers') {
if (get(user, 'primary_group_name') === 'managers') {
return ['managers'];
}
});

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import RestModel from "discourse/models/rest";
import computed from "ember-addons/ember-computed-decorators";
@ -232,15 +233,15 @@ Category.reopenClass({
slugFor(category, separator = "/") {
if (!category) return "";
const parentCategory = Ember.get(category, "parentCategory");
const parentCategory = get(category, "parentCategory");
let result = "";
if (parentCategory) {
result = Category.slugFor(parentCategory) + separator;
}
const id = Ember.get(category, "id"),
slug = Ember.get(category, "slug");
const id = get(category, "id"),
slug = get(category, "slug");
return !slug || slug.trim().length === 0
? `${result}${id}-category`

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { or, not, and } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax";
@ -882,12 +883,12 @@ export default RestModel.extend({
than you supplied if the post has already been loaded.
**/
storePost(post) {
// Calling `Ember.get(undefined)` raises an error
// Calling `get(undefined)` raises an error
if (!post) {
return;
}
const postId = Ember.get(post, "id");
const postId = get(post, "id");
if (postId) {
const existing = this._identityMap[post.get("id")];
@ -931,7 +932,7 @@ export default RestModel.extend({
this.set("topic.suggested_topics", result.suggested_topics);
}
const posts = Ember.get(result, "post_stream.posts");
const posts = get(result, "post_stream.posts");
if (posts) {
posts.forEach(p => {
@ -971,7 +972,7 @@ export default RestModel.extend({
this.set("topic.suggested_topics", result.suggested_topics);
}
const posts = Ember.get(result, "post_stream.posts");
const posts = get(result, "post_stream.posts");
if (posts) {
posts.forEach(p => this.storePost(store.createRecord("post", p)));

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { equal, and, or, not } from "@ember/object/computed";
import EmberObject from "@ember/object";
@ -282,7 +283,7 @@ const Post = RestModel.extend({
if (key === "reply_to_user" && value && oldValue) {
skip =
value.username === oldValue.username ||
Ember.get(value, "username") === Ember.get(oldValue, "username");
get(value, "username") === get(oldValue, "username");
}
if (!skip) {

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { alias, sort } from "@ember/object/computed";
import EmberObject from "@ember/object";
@ -110,7 +111,7 @@ const Site = RestModel.extend({
updateCategory(newCategory) {
const categories = this.categories;
const categoryId = Ember.get(newCategory, "id");
const categoryId = get(newCategory, "id");
const existingCategory = categories.findBy("id", categoryId);
// Don't update null permissions

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { NotificationLevels } from "discourse/lib/notification-levels";
import {
@ -390,8 +391,8 @@ const TopicTrackingState = Discourse.Model.extend({
);
}
let categoryId = category ? Ember.get(category, "id") : null;
let categoryName = category ? Ember.get(category, "name") : null;
let categoryId = category ? get(category, "id") : null;
let categoryName = category ? get(category, "name") : null;
if (name === "new") {
return this.countNew(categoryId);

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { not, notEmpty, equal, and, or } from "@ember/object/computed";
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
@ -378,7 +379,7 @@ const Topic = RestModel.extend({
this.set("bookmarking", true);
const stream = this.postStream;
const posts = Ember.get(stream, "posts");
const posts = get(stream, "posts");
const firstPost =
posts && posts[0] && posts[0].get("post_number") === 1 && posts[0];
const bookmark = !this.bookmarked;

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import DiscourseRoute from "discourse/routes/discourse";
export function buildGroupPage(type) {
@ -9,7 +10,7 @@ export function buildGroupPage(type) {
},
model(params, transition) {
let categoryId = Ember.get(transition.to, "queryParams.category_id");
let categoryId = get(transition.to, "queryParams.category_id");
return this.modelFor("group").findPosts({ type, categoryId });
},

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { cancel } from "@ember/runloop";
import { scheduleOnce } from "@ember/runloop";
@ -215,9 +216,9 @@ const TopicRoute = DiscourseRoute.extend({
setupParams(topic, params) {
const postStream = topic.get("postStream");
postStream.set("summary", Ember.get(params, "filter") === "summary");
postStream.set("summary", get(params, "filter") === "summary");
const usernames = Ember.get(params, "username_filters"),
const usernames = get(params, "username_filters"),
userFilters = postStream.get("userFilters");
userFilters.clear();

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import EmberObject from "@ember/object";
import {
default as computed,
@ -19,7 +20,7 @@ export default EmberObject.extend({
contextType: {
get(searchContext) {
if (searchContext) {
return Ember.get(searchContext, "type");
return get(searchContext, "type");
}
},
set(value, searchContext) {

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import Service from "@ember/service";
export default Service.extend({
@ -14,7 +15,7 @@ export default Service.extend({
getSetting(themeId, settingsKey) {
if (this._settings[themeId]) {
return Ember.get(this._settings[themeId], settingsKey);
return get(this._settings[themeId], settingsKey);
}
return null;
},

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { schedule } from "@ember/runloop";
import { createWidget } from "discourse/widgets/widget";
import { iconNode } from "discourse-common/lib/icon-library";
@ -558,7 +559,7 @@ export default createWidget("header", {
if (service) {
const ctx = service.get("searchContext");
if (ctx) {
return Ember.get(ctx, "type");
return get(ctx, "type");
}
}
}

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { searchContextDescription } from "discourse/lib/search";
import { h } from "virtual-dom";
import { createWidget } from "discourse/widgets/widget";
@ -52,8 +53,8 @@ createWidget("search-context", {
const result = [];
if (ctx) {
const description = searchContextDescription(
Ember.get(ctx, "type"),
Ember.get(ctx, "user.username") || Ember.get(ctx, "category.name")
get(ctx, "type"),
get(ctx, "user.username") || get(ctx, "category.name")
);
result.push(
h("label", [

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { debounce } from "@ember/runloop";
import { later } from "@ember/runloop";
import { popupAjaxError } from "discourse/lib/ajax-error";
@ -99,7 +100,7 @@ export default createWidget("search-menu", {
const contextEnabled = searchData.contextEnabled;
const ctx = contextEnabled ? this.searchContext() : null;
const type = ctx ? Ember.get(ctx, "type") : null;
const type = ctx ? get(ctx, "type") : null;
let url = "/search";
const params = [];

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { makeArray } from "discourse/lib/utilities";
import MultiSelectComponent from "select-kit/components/multi-select";
import Category from "discourse/models/category";
@ -39,7 +40,7 @@ export default MultiSelectComponent.extend({
filterComputedContent(computedContent, computedValues, filter) {
const regex = new RegExp(filter, "i");
return computedContent.filter(category =>
this._normalize(Ember.get(category, "name")).match(regex)
this._normalize(get(category, "name")).match(regex)
);
},

View File

@ -1,3 +1,5 @@
import { isEmpty } from "@ember/utils";
import { get } from "@ember/object";
import { makeArray } from "discourse/lib/utilities";
import Category from "discourse/models/category";
import ComboBox from "select-kit/components/combo-box";
@ -6,7 +8,6 @@ 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 } = Ember;
export default ComboBox.extend(TagsMixin, {
allowContentReplacement: true,
@ -168,9 +169,7 @@ export default ComboBox.extend(TagsMixin, {
computeHeaderContent() {
let content = this._super(...arguments);
const joinedTags = this.selection
.map(s => Ember.get(s, "value"))
.join(", ");
const joinedTags = this.selection.map(s => get(s, "value")).join(", ");
if (isEmpty(this.selection)) {
content.label = I18n.t("tagging.choose_for_topic");
@ -198,7 +197,7 @@ export default ComboBox.extend(TagsMixin, {
if (this.selection) {
data.selected_tags = this.selection
.map(s => Ember.get(s, "value"))
.map(s => get(s, "value"))
.slice(0, 100);
}

View File

@ -1,3 +1,4 @@
import { get } from "@ember/object";
import { makeArray } from "discourse/lib/utilities";
import { isEmpty } from "@ember/utils";
import { throttle } from "@ember/runloop";
@ -298,7 +299,7 @@ export default Mixin.create({
.slice()
.reverse()
.some(selection => {
if (!Ember.get(selection, "locked")) {
if (!get(selection, "locked")) {
this.highlightSelection(selection);
return true;
}