refactor: remove getNonNullValues, replace with _.ominBy and _.isNull (lodash)
ref: https://stackoverflow.com/a/70554734/11408375
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { isNull, omitBy } from "lodash";
|
||||
import BASE_URL from "../config";
|
||||
import { getNonNullValues } from "../../common/utils";
|
||||
import { Channel, UpdateChannelDTO, UpdatePinnedMessageDTO } from "../../types/channel";
|
||||
|
||||
interface StoredChannel extends Channel {
|
||||
@@ -70,7 +70,8 @@ const channelsSlice = createSlice({
|
||||
break;
|
||||
}
|
||||
default:
|
||||
state.byId[gid] = { ...state.byId[gid]!, ...getNonNullValues(rest) };
|
||||
// old code: state.byId[gid] = { ...state.byId[gid]!, ...getNonNullValues(rest) };
|
||||
state.byId[gid] = { ...state.byId[gid]!, ...omitBy(rest, isNull) };
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { getNonNullValues } from "../../common/utils";
|
||||
import { isNull, omitBy } from "lodash";
|
||||
import BASE_URL from "../config";
|
||||
import { User } from "../../types/auth";
|
||||
import { UserLog, UserState } from "../../types/sse";
|
||||
@@ -46,9 +46,10 @@ const contactsSlice = createSlice({
|
||||
changeLogs.forEach(({ action, uid, ...rest }) => {
|
||||
switch (action) {
|
||||
case "update": {
|
||||
const vals = getNonNullValues(rest);
|
||||
const vals = omitBy(rest, isNull);
|
||||
if (state.byId[uid]) {
|
||||
Object.keys(vals).forEach((k) => {
|
||||
// @ts-ignore
|
||||
state.byId[uid]![k] = vals[k];
|
||||
if (k == "avatar_updated_at") {
|
||||
state.byId[uid]!.avatar = `${BASE_URL}/resource/avatar?uid=${uid}&t=${vals[k]}`;
|
||||
|
||||
Reference in New Issue
Block a user