Skip to content

Commit f4e5f31

Browse files
Merge pull request #8 from bigopon/master
chore(typings): add typings
2 parents 6dd5d5b + 8b8c781 commit f4e5f31

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"unpkg": "min.js",
66
"main": "cjs/index.js",
77
"module": "esm/index.js",
8+
"types": "types.d.ts",
89
"scripts": {
910
"build": "npm run cjs && npm run bundle && npm run min && npm run test && npm run size",
1011
"bundle": "rollup --config rollup.config.js && npm run cleanup",

types.d.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
export interface IDomDiffNodeMarkerOptions<T = Node> {
2+
/**
3+
* A specific live node to use as boundary for all nodes operations.
4+
* With live nodes [a,d] and {before: d}, the operation [] => [b, c]
5+
* would place nodes right before d, resulting a live collection of [a, b, c, d].
6+
*
7+
* `before` doesn't necessarily have to be a node
8+
*/
9+
before: T;
10+
}
11+
12+
export interface IDomDiffOptionsGenericComparisonFn {
13+
/**
14+
* A callback to compare between two generic objects, each could be a node or anything. returns `true` to indicate they are the same
15+
*/
16+
compare: <T1 = any, T2 = any>(currentNode: T1, futureNode: T2) => boolean;
17+
}
18+
19+
export interface IDomDiffOPtionsEachNodeCallbackFn {
20+
/**
21+
* The optional function is invoked per each operation on the list of current"Nodes".
22+
* This can be useful to represent node through wrappers, whenever that is needed.
23+
* @param info
24+
* `1` when the item/node is being appended
25+
* `0` when the item/node is being used as insert _before_ reference
26+
* `-0` when the item/node is being used as insert _after_ reference
27+
* `-1` when the item/node is being removed
28+
*/
29+
node: <T = any>(generic: T, info: -1 | -0 | 0 | 1) => Node;
30+
}
31+
32+
/**
33+
* A vDOM-less implementation of the [petit-dom](https://github.com/yelouafi/petit-dom) diffing logic
34+
* that will mutate child nodes the first argument - parentNode
35+
* @param parentNode Where changes happen
36+
* @param currentNodes Array of current items / nodes.
37+
* @param futureNodes Array of future items / nodes
38+
*/
39+
export default function domdiff<TCurrentItems extends any[], TFutureItems extends any[]>(
40+
parentNode: Node,
41+
currentNodes: TCurrentItems,
42+
futureNodes: TFutureItems,
43+
options?: IDomDiffNodeMarkerOptions | IDomDiffOptionsGenericComparisonFn | IDomDiffOPtionsEachNodeCallbackFn
44+
): void;

0 commit comments

Comments
 (0)