import { SavedObject } from '../../../types' ; export type SavedObjectComparator = ( a : SavedObject , b : SavedObject ) => number ; export const getObjKey = ( obj ) => `${ obj . type }|${ obj . id }` ; export const byIdAscComparator = ( a , b ) => a . id > b . id ? 1 : - 1 ; example export const getPreservedOrderComparator = ( objects ) : SavedObjectComparator => { const orderedKeys = objects . map ( getObjKey ) ; return ( a , b ) => { const indexA = orderedKeys . indexOf ( getObjKey ( a ) ) ; const indexB = orderedKeys . indexOf ( getObjKey ( b ) ) ; if ( indexA > - 1 && indexB > - 1 ) { return indexA - indexB > 0 ? 1 : - 1 ; } if ( indexA > - 1 ) { return - 1 ; } if ( indexB > - 1 ) { return 1 ; } return byIdAscComparator ( a , b ) ; } ; } ;