refactor deep-diff.d.ts

This commit is contained in:
vvakame 2014-09-15 23:32:25 +09:00
parent 7f2b246029
commit e4aa121ada
2 changed files with 27 additions and 30 deletions

View File

@ -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);

View File

@ -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;
}
}