import { ComponentHandle } from './Component2.js'; export type Has = { Component: Comp; kind: 'has'; __isFilter: true; toString(): string; }; export const has = ( Component: Comp, ): Has => ({ Component, kind: 'has', __isFilter: true, toString() { return `has(${Component.name})`; }, }); export type Not = { Component: Comp; kind: 'not'; __isFilter: true; toString(): string; }; export const not = ( Component: Comp, ): Not => ({ Component, kind: 'not', __isFilter: true, toString() { return `not(${Component.name})`; }, }); export type Changed = { Component: Comp; kind: 'changed'; __isFilter: true; toString(): string; }; export const changed = ( Component: Comp, ): Changed => ({ Component, kind: 'changed', __isFilter: true, toString() { return `changed(${Component.name})`; }, }); export type OneOf = { Components: Comps; kind: 'oneOf'; __isFilter: true; toString(): string; }; export const oneOf = ( ...Components: Comps ): OneOf => ({ Components, kind: 'oneOf', __isFilter: true, toString() { return `oneOf(${Components.map((Comp) => Comp.name) .sort() .join(', ')})`; }, }); /** @deprecated - use oneOf */ export const any = oneOf; export type Filter = | Not | Has | Changed | OneOf; export const isFilter = (thing: any): thing is Filter => thing.__isFilter === true; export const isNotFilter = (fil: Filter): fil is Not => fil.kind === 'not'; export const isHasFilter = (fil: Filter): fil is Has => fil.kind === 'has'; export const isChangedFilter = ( fil: Filter, ): fil is Changed => fil.kind === 'changed'; export const isOneOfFilter = ( fil: Filter, ): fil is OneOf => fil.kind === 'oneOf';