|
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; |
3 | 10 | }
|
4 | 11 |
|
5 | 12 | export interface IDomDiffOptionsGenericComparisonFn {
|
6 | 13 | /**
|
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 |
8 | 15 | */
|
9 |
| - compare: (currentNode: Node, futureNode: Node) => boolean; |
| 16 | + compare: <T1 = any, T2 = any>(currentNode: T1, futureNode: T2) => boolean; |
10 | 17 | }
|
11 | 18 |
|
12 | 19 | export interface IDomDiffOPtionsEachNodeCallbackFn {
|
13 | 20 | /**
|
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". |
15 | 22 | * This can be useful to represent node through wrappers, whenever that is needed.
|
16 | 23 | * @param info
|
17 | 24 | * `1` when the item/node is being appended
|
18 | 25 | * `0` when the item/node is being used as insert _before_ reference
|
19 | 26 | * `-0` when the item/node is being used as insert _after_ reference
|
20 | 27 | * `-1` when the item/node is being removed
|
21 | 28 | */
|
22 |
| - node: (generic: Node, info: -1 | -0 | 0 | 1) => Node; |
| 29 | + node: <T = any>(generic: T, info: -1 | -0 | 0 | 1) => Node; |
23 | 30 | }
|
24 | 31 |
|
25 | 32 | /**
|
26 | 33 | * A vDOM-less implementation of the [petit-dom](https://github.com/yelouafi/petit-dom) diffing logic
|
27 | 34 | * that will mutate child nodes the first argument - parentNode
|
28 | 35 | * @param parentNode Where changes happen
|
29 |
| - * @param currentNodes Array of current items / nodes |
| 36 | + * @param currentNodes Array of current items / nodes. |
30 | 37 | * @param futureNodes Array of future items / nodes
|
31 | 38 | */
|
32 |
| -export default function domdiff( |
| 39 | +export default function domdiff<TCurrentItems extends any[], TFutureItems extends any[]>( |
33 | 40 | parentNode: Node,
|
34 |
| - currentNodes: ArrayLike<Node>, |
35 |
| - futureNodes: ArrayLike<Node>, |
| 41 | + currentNodes: TCurrentItems, |
| 42 | + futureNodes: TFutureItems, |
36 | 43 | options?: IDomDiffNodeMarkerOptions | IDomDiffOptionsGenericComparisonFn | IDomDiffOPtionsEachNodeCallbackFn
|
37 | 44 | ): void;
|
0 commit comments