Skip to content

Commit 4244595

Browse files
committed
refactor: fix types, switch cases
1 parent f29a37f commit 4244595

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/definitions.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import type { ObjectId, MongooseModel, MongooseDocument } from 'mongoose';
55
import MHD, { revertChanges } from './diff';
66

77
export type OptionsT = {|
8-
diffCollectionName: ?string,
9-
orderIndependent: ?boolean,
8+
diffCollectionName?: string,
9+
orderIndependent?: boolean,
1010
|};
1111

12-
export type DiffModelT = MongooseModel & typeof DiffDoc;
13-
1412
export type KindT = 'E' | 'N' | 'D' | 'A';
1513

14+
export class ItemDoc /* :: extends Mongoose$Document */ {
15+
k: KindT;
16+
l: ?any;
17+
r: ?any;
18+
}
1619
export type RawChangeT = {|
1720
k: KindT,
1821
p: Array<string>,
@@ -22,12 +25,6 @@ export type RawChangeT = {|
2225
it?: $Shape<ItemDoc>,
2326
|};
2427

25-
export class ItemDoc /* :: extends Mongoose$Document */ {
26-
k: KindT;
27-
l: ?any;
28-
r: ?any;
29-
}
30-
3128
export class ChangeDoc /* :: extends Mongoose$Document */ {
3229
k: KindT;
3330
p: Array<string>;
@@ -82,3 +79,5 @@ export class DiffDoc /* :: extends Mongoose$Document */ {
8279
return MHD.findDiff(initialDoc, currentDoc);
8380
}
8481
}
82+
83+
export type DiffModelT = MongooseModel & typeof DiffDoc;

src/diff.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
/* eslint-disable no-param-reassign */
2+
/* eslint-disable no-param-reassign, no-plusplus */
33

44
import {
55
realTypeOf,
@@ -204,7 +204,7 @@ export const revertChanges = (target: any, changes: Array<RawChangeT>): any => {
204204
delete it[change.p[i]];
205205
break;
206206
default:
207-
'';
207+
it[change.p[i]] = {};
208208
}
209209
});
210210
return copyTarget;

src/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,12 @@ export const revertArrayChange = (arr: Array<any>, index: number, change: any):
143143
delete element[change.p[j]];
144144
break;
145145
default:
146-
'';
146+
return [];
147147
}
148148
} else {
149149
// the array item is different...
150150
switch (change.k) {
151151
case 'A':
152-
// $FlowFixMe
153152
revertArrayChange(arr[index], change.i, change.it);
154153
break;
155154
case 'D':
@@ -162,7 +161,7 @@ export const revertArrayChange = (arr: Array<any>, index: number, change: any):
162161
arr = arrayRemove(arr, index);
163162
break;
164163
default:
165-
'';
164+
arr = [];
166165
}
167166
}
168167
return arr;
@@ -171,6 +170,7 @@ export const revertArrayChange = (arr: Array<any>, index: number, change: any):
171170
export const deepClone = (obj: any): any => {
172171
if (realTypeOf(obj) === 'object') {
173172
const clone = { ...obj };
173+
// eslint-disable-next-line no-restricted-syntax
174174
for (const k in clone) {
175175
if (clone.hasOwnProperty(k)) {
176176
clone[k] = deepClone(clone[k]);

0 commit comments

Comments
 (0)