import difference from 'lodash/difference' ; import camelCase from 'lodash/camelCase' ; import { InstanceProps } from '../reconciler/instance' ; import { SIMPLIFY_COMPONENTS } from '../constants' ; const isSubsetOf = < T > ( subset , fullset ) => difference ( subset , fullset ) . length === 0 ; const filterPropsAndEventsName = ( names ) => { const props = [ ] ; const events = [ ] ; for ( const name of names ) { if ( name . startsWith ( 'on' ) ) { events . push ( camelCase ( name . replace ( /^on/ , '' ) ) ) ; } else { props . push ( name ) ; } } return { props , events , } ; } ; export const findSimplifyId = ( type , names ) => { const { props , events } = filterPropsAndEventsName ( Object . keys ( names ) ) ; const index = SIMPLIFY_COMPONENTS . findIndex ( item => item . name === type && isSubsetOf ( props , item . properties ) && isSubsetOf ( events , item . events ) ) ; return index === - 1 ? undefined : index ; } ;