diff --git a/types/morphdom/index.d.ts b/types/morphdom/index.d.ts new file mode 100644 index 0000000000..61df5a9a78 --- /dev/null +++ b/types/morphdom/index.d.ts @@ -0,0 +1,24 @@ +// Type definitions for morphdom 2.3 +// Project: https://github.com/patrick-steele-idem/morphdom +// Definitions by: arvitaly +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface MorphDomOptions { + getNodeKey?: (node: Node) => any; + onBeforeNodeAdded?: (node: Node) => Node; + onNodeAdded?: (node: Node) => Node; + onBeforeElUpdated?: (fromEl: HTMLElement, toEl: HTMLElement) => boolean; + onElUpdated?: (el: HTMLElement) => void; + onBeforeNodeDiscarded?: (node: Node) => boolean; + onNodeDiscarded?: (node: Node) => void; + onBeforeElChildrenUpdated?: (fromEl: HTMLElement, toEl: HTMLElement) => boolean; + childrenOnly?: boolean; +} + +declare function morphdom( + fromNode: Node, + toNode: Node | string, + options?: MorphDomOptions, +): void; + +export = morphdom; diff --git a/types/morphdom/morphdom-tests.ts b/types/morphdom/morphdom-tests.ts new file mode 100644 index 0000000000..e2c7476561 --- /dev/null +++ b/types/morphdom/morphdom-tests.ts @@ -0,0 +1,20 @@ +import morphdom = require("morphdom"); + +declare var node1: Node; +declare var node2: Node; +declare var el1: HTMLElement; +declare var el2: HTMLElement; + +morphdom(node1, node2); +morphdom(node1, node2, {}); +morphdom(node1, node2, { + childrenOnly: true, + getNodeKey: (node) => null, + onBeforeElChildrenUpdated: (el1, el2) => true, + onBeforeElUpdated: (el1, el2) => true, + onBeforeNodeAdded: (node) => node1, + onBeforeNodeDiscarded: (node) => false, + onElUpdated: (el) => null, + onNodeAdded: (node) => node2, + onNodeDiscarded: (node) => null, +}); diff --git a/types/morphdom/tsconfig.json b/types/morphdom/tsconfig.json new file mode 100644 index 0000000000..8fccfdf66e --- /dev/null +++ b/types/morphdom/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "morphdom-tests.ts" + ] +} \ No newline at end of file diff --git a/types/morphdom/tslint.json b/types/morphdom/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/morphdom/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}