REFACTOR: Remove `_.isEqual`
This commit is contained in:
parent
c4079780be
commit
f365d4639a
|
@ -1,7 +1,9 @@
|
||||||
// a fairly simple deep merge based on: https://gist.github.com/ahtcx/0cd94e62691f539160b32ecda18af3d6
|
// a fairly simple deep merge based on: https://gist.github.com/ahtcx/0cd94e62691f539160b32ecda18af3d6
|
||||||
export function merge(...objects) {
|
function isObject(obj) {
|
||||||
const isObject = obj => obj && typeof obj === "object";
|
return obj && typeof obj === "object";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function merge(...objects) {
|
||||||
function deepMergeInner(target, source) {
|
function deepMergeInner(target, source) {
|
||||||
Object.keys(source).forEach(key => {
|
Object.keys(source).forEach(key => {
|
||||||
const targetValue = target[key];
|
const targetValue = target[key];
|
||||||
|
@ -35,3 +37,19 @@ export function merge(...objects) {
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deepEqual(obj1, obj2) {
|
||||||
|
if (obj1 === obj2) {
|
||||||
|
return true;
|
||||||
|
} else if (isObject(obj1) && isObject(obj2)) {
|
||||||
|
if (Object.keys(obj1).length !== Object.keys(obj2).length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (var prop in obj1) {
|
||||||
|
if (!deepEqual(obj1[prop], obj2[prop])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import discourseComputed, { on } from "discourse-common/utils/decorators";
|
||||||
import PreloadStore from "discourse/lib/preload-store";
|
import PreloadStore from "discourse/lib/preload-store";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
|
import { deepEqual } from "discourse-common/lib/object";
|
||||||
|
|
||||||
function isNew(topic) {
|
function isNew(topic) {
|
||||||
return (
|
return (
|
||||||
|
@ -115,7 +116,7 @@ const TopicTrackingState = EmberObject.extend({
|
||||||
if (["new_topic", "unread", "read"].includes(data.message_type)) {
|
if (["new_topic", "unread", "read"].includes(data.message_type)) {
|
||||||
tracker.notify(data);
|
tracker.notify(data);
|
||||||
const old = tracker.states["t" + data.topic_id];
|
const old = tracker.states["t" + data.topic_id];
|
||||||
if (!_.isEqual(old, data.payload)) {
|
if (!deepEqual(old, data.payload)) {
|
||||||
tracker.states["t" + data.topic_id] = data.payload;
|
tracker.states["t" + data.topic_id] = data.payload;
|
||||||
tracker.notifyPropertyChange("states");
|
tracker.notifyPropertyChange("states");
|
||||||
tracker.incrementMessageCount();
|
tracker.incrementMessageCount();
|
||||||
|
|
|
@ -11,6 +11,7 @@ import Session from "discourse/models/session";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
|
import { deepEqual } from "discourse-common/lib/object";
|
||||||
|
|
||||||
// A helper to build a topic route for a filter
|
// A helper to build a topic route for a filter
|
||||||
function filterQueryParams(params, defaultParams) {
|
function filterQueryParams(params, defaultParams) {
|
||||||
|
@ -39,7 +40,7 @@ function findTopicList(store, tracking, filter, filterParams, extras) {
|
||||||
cachedList &&
|
cachedList &&
|
||||||
cachedList.get("filter") === filter &&
|
cachedList.get("filter") === filter &&
|
||||||
(cachedList.get("topics.length") || 0) > cachedList.get("per_page") &&
|
(cachedList.get("topics.length") || 0) > cachedList.get("per_page") &&
|
||||||
_.isEqual(cachedList.get("listParams"), filterParams)
|
deepEqual(cachedList.get("listParams"), filterParams)
|
||||||
) {
|
) {
|
||||||
cachedList.set("loaded", true);
|
cachedList.set("loaded", true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue