Browse Source

Remove CommentApp state `update` util

- The `update` util's types are not compatible with future TS v5 adoption.
- This util is simply a wrapper around `Object.assign` and only used in three places.
- Instead use the Object.assign in place for simplicity instead and remove the `update` util.
LB Johnston 1 year ago
parent
commit
fb340f1971

+ 2 - 3
client/src/components/CommentApp/state/comments.ts

@@ -1,7 +1,6 @@
 import produce, { enableMapSet, enableES5 } from 'immer';
 import type { Annotation } from '../utils/annotation';
 import * as actions from '../actions/comments';
-import { update } from './utils';
 
 enableES5();
 enableMapSet();
@@ -225,7 +224,7 @@ export const reducer = produce(
           if (action.update.newText && action.update.newText.length === 0) {
             break;
           }
-          update(comment, action.update);
+          Object.assign(comment, action.update);
         }
         break;
       }
@@ -280,7 +279,7 @@ export const reducer = produce(
         if (action.update.newText && action.update.newText.length === 0) {
           break;
         }
-        update(reply, action.update);
+        Object.assign(reply, action.update);
         break;
       }
       case actions.DELETE_REPLY: {

+ 1 - 2
client/src/components/CommentApp/state/settings.ts

@@ -1,7 +1,6 @@
 import produce from 'immer';
 import * as actions from '../actions/settings';
 import type { Author } from './comments';
-import { update } from './utils';
 
 export interface SettingsState {
   user: Author | null;
@@ -20,7 +19,7 @@ export const reducer = produce(
   (draft: SettingsState, action: actions.Action) => {
     switch (action.type) {
       case actions.UPDATE_GLOBAL_SETTINGS:
-        update(draft, action.update);
+        Object.assign(draft, action.update);
         break;
       default:
         break;

+ 0 - 3
client/src/components/CommentApp/state/utils.ts

@@ -1,3 +0,0 @@
-export function update<T>(base: T, updatePartial: Partial<T>): T {
-  return Object.assign(base, updatePartial);
-}