import { Entity } from "./entity" ; /**
 * Interface that conveys an updated entity as well as information
 * on the update-type
 */ export interface UpdatedEntity < T extends Entity > { /**
     * The updated entity
     */ entity : T ; /**
     * The type of the update, either:
     * "new" - a new entity was created,
     * "update" - an existing entity was updated
     * "remove" - the entity was deleted
     */ type : "new" | "update" | "remove" ; } param next param entities return export function applyUpdate < T extends Entity > ( entities , next ) { if ( ! next || ! next . entity ) { return entities ; } switch ( next . type ) { case "new" : return [ next . entity ] . concat ( entities ) ; case "update" : return entities . map ( ( e ) => e . getId ( ) === next . entity . getId ( ) ? next . entity : e ) ; case "remove" : return entities . filter ( ( e ) => e . getId ( ) !== next . entity . getId ( ) ) ; } }