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
@@ -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`
@@ -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)));
@@ -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) {
@@ -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
@@ -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);
@@ -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;