|
| 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