File tree Expand file tree Collapse file tree 1 file changed +33
-5
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +33
-5
lines changed
Original file line number Diff line number Diff line change 1
- export function diff ( originalObj : object , updatedObj : object ) : object
1
+ type DeepPartial < T > = {
2
+ [ K in keyof T ] ?: DeepPartial < T [ K ] >
3
+ }
2
4
3
- export function addedDiff ( originalObj : object , updatedObj : object ) : object
5
+ interface IDictionary < T > {
6
+ [ key : string ] : T ;
7
+ }
4
8
5
- export function deletedDiff ( originalObj : object , updatedObj : object ) : object
9
+ /*
10
+ In "deep-object-diff" there're 2 scenarios for a property diff:
11
+ 1. If the property is an object or primitive, the diff is a deep partial;
12
+ 2. If the property is an array, the diff is a dictionary.
13
+ Its keys are indices, and the values are deep partials of the change.
14
+ */
15
+ type PropertyDiff < T > = T extends Array < infer Elem >
16
+ ? IDictionary < Elem >
17
+ : DeepPartial < T > ;
6
18
7
- export function updatedDiff ( originalObj : object , updatedObj : object ) : object
19
+ export type Diff < T > = {
20
+ [ P in keyof T ] ?: PropertyDiff < T [ P ] > ;
21
+ } ;
8
22
9
- export function detailedDiff ( originalObj : object , updatedObj : object ) : object
23
+ export interface IDetailedDiff < T > {
24
+ added : Diff < T > ;
25
+ deleted : Diff < T > ;
26
+ updated : Diff < T > ;
27
+ }
28
+
29
+ export function diff < T > ( originalObj : T , updatedObj : T ) : Diff < T >
30
+
31
+ export function addedDiff < T > ( originalObj : T , updatedObj : T ) : Diff < T >
32
+
33
+ export function deletedDiff < T > ( originalObj : T , updatedObj : T ) : Diff < T >
34
+
35
+ export function updatedDiff < T > ( originalObj : T , updatedObj : T ) : Diff < T >
36
+
37
+ export function detailedDiff < T > ( originalObj : T , updatedObj : T ) : IDetailedDiff < T >
You can’t perform that action at this time.
0 commit comments