mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
refactor deep-diff.d.ts
This commit is contained in:
parent
7f2b246029
commit
e4aa121ada
@ -1,7 +1,7 @@
|
||||
/// <reference path="./deep-diff.d.ts" />
|
||||
|
||||
import deepDiff = require('deep-diff');
|
||||
var diff = deepDiff.diff;
|
||||
import _deepDiff = require('deep-diff');
|
||||
var diff = _deepDiff.diff;
|
||||
|
||||
var lhs = {
|
||||
name: 'my object',
|
||||
@ -23,16 +23,15 @@ var rhs = {
|
||||
}
|
||||
};
|
||||
|
||||
var differences: IDiff[] = diff(lhs, rhs);
|
||||
var differences: deepDiff.IDiff[] = diff(lhs, rhs);
|
||||
|
||||
console.log(differences);
|
||||
|
||||
|
||||
// --------------------------
|
||||
|
||||
|
||||
var observableDiff = deepDiff.observableDiff;
|
||||
var applyChange = deepDiff.applyChange;
|
||||
var observableDiff = _deepDiff.observableDiff;
|
||||
var applyChange = _deepDiff.applyChange;
|
||||
|
||||
var lhs = {
|
||||
name: 'my object',
|
||||
@ -54,7 +53,7 @@ var rhs = {
|
||||
}
|
||||
};
|
||||
|
||||
observableDiff(lhs, rhs, function (d: IDiff) {
|
||||
observableDiff(lhs, rhs, function (d: deepDiff.IDiff) {
|
||||
// Apply all changes except those to the 'name' property...
|
||||
if (d.path.length !== 1 || d.path.join('.') !== 'name') {
|
||||
applyChange(lhs, rhs, d);
|
||||
|
||||
44
deep-diff/deep-diff.d.ts
vendored
44
deep-diff/deep-diff.d.ts
vendored
@ -3,27 +3,26 @@
|
||||
// Definitions by: ZauberNerd <https://github.com/ZauberNerd/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
interface IDiff {
|
||||
kind: string;
|
||||
path: string[];
|
||||
lhs: any;
|
||||
rhs: any;
|
||||
index?: number;
|
||||
item?: IDiff;
|
||||
}
|
||||
|
||||
interface IAccumulator {
|
||||
push(diff: IDiff): void;
|
||||
length: number;
|
||||
}
|
||||
|
||||
interface IPrefilter {
|
||||
(path: string[], key: string): boolean;
|
||||
}
|
||||
|
||||
declare module deepDiff {
|
||||
export interface IDeepDiff {
|
||||
interface IDiff {
|
||||
kind: string;
|
||||
path: string[];
|
||||
lhs: any;
|
||||
rhs: any;
|
||||
index?: number;
|
||||
item?: IDiff;
|
||||
}
|
||||
|
||||
interface IAccumulator {
|
||||
push(diff: IDiff): void;
|
||||
length: number;
|
||||
}
|
||||
|
||||
interface IPrefilter {
|
||||
(path: string[], key: string): boolean;
|
||||
}
|
||||
|
||||
interface IDeepDiff {
|
||||
diff(): IDiff;
|
||||
diff(lhs: Object, rhs: Object, prefilter?: IPrefilter, acc?: IAccumulator): IDiff[];
|
||||
observableDiff(lhs: Object, rhs: Object, changes: Function, prefilter?: IPrefilter, path?: string[], key?: string, stack?: Object[]): void;
|
||||
@ -35,8 +34,7 @@ declare module deepDiff {
|
||||
}
|
||||
}
|
||||
|
||||
declare var diff: deepDiff.IDeepDiff;
|
||||
|
||||
declare module "deep-diff" {
|
||||
var diff: deepDiff.IDeepDiff;
|
||||
export = diff;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user