11// @flow
2+ import isEqual from 'lodash.isEqual' ;
3+ import React from 'react' ;
24export type LayoutItemRequired = { w : number , h : number , x : number , y : number , i : string } ;
35export type LayoutItem = LayoutItemRequired &
46 { minW ?: number , minH ?: number , maxW ?: number , maxH ?: number ,
@@ -15,7 +17,6 @@ export type DragCallbackData = {
1517export type DragEvent = { e : Event } & DragCallbackData ;
1618export type Size = { width : number , height : number } ;
1719export type ResizeEvent = { e : Event , node : HTMLElement , size : Size } ;
18- import type React from 'react' ;
1920
2021const isProduction = process . env . NODE_ENV === 'production' ;
2122
@@ -53,10 +54,16 @@ export function cloneLayoutItem(layoutItem: LayoutItem): LayoutItem {
5354 } ;
5455}
5556
57+ /**
58+ * Comparing React `children` is a bit difficult. This is a good way to compare them.
59+ * This will catch differences in keys, order, and length.
60+ */
61+ export function childrenEqual ( a : Array < React . Element < any >> , b : Array < React . Element < any >> ) : boolean {
62+ return isEqual ( React . Children . map ( a , c => c . key ) , React . Children . map ( b , c => c . key ) ) ;
63+ }
64+
5665/**
5766 * Given two layoutitems, check if they collide.
58- *
59- * @return {Boolean } True if colliding.
6067 */
6168export function collides ( l1 : LayoutItem , l2 : LayoutItem ) : boolean {
6269 if ( l1 === l2 ) return false ; // same element
0 commit comments