Skip to content

Commit 8b8c781

Browse files
committed
fix(typings): adjust description / typings
1 parent b7210c6 commit 8b8c781

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

types.d.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
1-
export interface IDomDiffNodeMarkerOptions {
2-
before: Node;
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;
310
}
411

512
export interface IDomDiffOptionsGenericComparisonFn {
613
/**
7-
* A callback to compare between two generic nodes. returns `true` to indicate they are the same
14+
* A callback to compare between two generic objects, each could be a node or anything. returns `true` to indicate they are the same
815
*/
9-
compare: (currentNode: Node, futureNode: Node) => boolean;
16+
compare: <T1 = any, T2 = any>(currentNode: T1, futureNode: T2) => boolean;
1017
}
1118

1219
export interface IDomDiffOPtionsEachNodeCallbackFn {
1320
/**
14-
* The optional `{node: (generic, info) => node}` is invoked per each operation on the DOM.
21+
* The optional function is invoked per each operation on the list of current"Nodes".
1522
* This can be useful to represent node through wrappers, whenever that is needed.
1623
* @param info
1724
* `1` when the item/node is being appended
1825
* `0` when the item/node is being used as insert _before_ reference
1926
* `-0` when the item/node is being used as insert _after_ reference
2027
* `-1` when the item/node is being removed
2128
*/
22-
node: (generic: Node, info: -1 | -0 | 0 | 1) => Node;
29+
node: <T = any>(generic: T, info: -1 | -0 | 0 | 1) => Node;
2330
}
2431

2532
/**
2633
* A vDOM-less implementation of the [petit-dom](https://github.com/yelouafi/petit-dom) diffing logic
2734
* that will mutate child nodes the first argument - parentNode
2835
* @param parentNode Where changes happen
29-
* @param currentNodes Array of current items / nodes
36+
* @param currentNodes Array of current items / nodes.
3037
* @param futureNodes Array of future items / nodes
3138
*/
32-
export default function domdiff(
39+
export default function domdiff<TCurrentItems extends any[], TFutureItems extends any[]>(
3340
parentNode: Node,
34-
currentNodes: ArrayLike<Node>,
35-
futureNodes: ArrayLike<Node>,
41+
currentNodes: TCurrentItems,
42+
futureNodes: TFutureItems,
3643
options?: IDomDiffNodeMarkerOptions | IDomDiffOptionsGenericComparisonFn | IDomDiffOPtionsEachNodeCallbackFn
3744
): void;

0 commit comments

Comments
 (0)