import { isEmpty } from '@typed/objects' ; import { StrMap , StrMapDiff } from '../model' ; import { isBooleanAttribute } from './isBooleanAttribute' ; const EMPTY = [ ] ; const empty = { removed : EMPTY , updated : EMPTY , } ; export function diffAttributes ( currentMap , updatedMap ) { if ( isEmpty ( currentMap ) && isEmpty ( updatedMap ) ) { return empty ; } const updated = [ ] ; const removed = [ ] ; const currentKeys = Object . keys ( currentMap ) ; const updatedKeys = Object . keys ( updatedMap ) ; for ( const key of updatedKeys ) { const currentValue = currentMap [ key ] ; const updatedValue = updatedMap [ key ] ; if ( currentValue !== updatedValue ) { if ( ! updatedValue && isBooleanAttribute ( key ) ) { removed . push ( [ key , currentValue ] ) ; } else { updated . push ( [ key , updatedValue ] ) ; } } } for ( const key of currentKeys ) { if ( ! ( key in updatedMap ) ) { removed . push ( [ key , currentMap [ key ] ] ) ; } } return { removed , updated , } ; }