Beispiel #1
0
 it('should merge diff for an update of property after its child prpoerty updates', () => {
     let oldValue = {x: {y: {a: 1, b: 2}}};
     let newValue = {x: 1};
     let x = {
         x: {
             y: {
                 c: createDiffNode('add', undefined, 3)
             }
         }
     };
     let y = {
         x: createDiffNode('change', oldValue.x /* 没用 */, 1)
     };
     let node = mergeDiff(x, y, oldValue, newValue);
     expect(node).toEqual({
         x: {
             changeType: 'change',
             oldValue: {
                 y: {
                     a: 1,
                     b: 2
                 }
             },
             newValue: 1
         }
     });
 });
Beispiel #2
0
 it('should merge diff for an update of property after its parent prpoerty updates', () => {
     let oldValue = {x: {y: {a: 1, b: 2}}};
     let newValue = {x: {y: [1]}};
     let x = {
         x: createDiffNode('change', oldValue.x, {y: []})
     };
     let y = {
         x: {
             y: createDiffNode('change', {y: []} /* 没用 */, {y: [1]})
         }
     };
     let node = mergeDiff(x, y, oldValue, newValue);
     expect(node).toEqual({
         x: {
             changeType: 'change',
             oldValue: {
                 y: {
                     a: 1,
                     b: 2
                 }
             },
             newValue: {
                 y: [1]
             }
         }
     });
 });
Beispiel #3
0
 it('should merge diffs from different properties', () => {
     let oldValue = {x: {a: 1, b: 2}};
     let newValue = {x: {a: 2, b: 3}};
     let x = {
         x: {
             a: createDiffNode('change', 1, 2)
         }
     };
     let y = {
         x: {
             b: createDiffNode('change', 2, 3)
         }
     };
     let node = mergeDiff(x, y, oldValue, newValue);
     expect(node).toEqual({
         x: {
             a: {
                 changeType: 'change',
                 oldValue: 1,
                 newValue: 2
             },
             b: {
                 changeType: 'change',
                 oldValue: 2,
                 newValue: 3
             }
         }
     });
 });