UNPKG

typir

Version:

General purpose type checking library

70 lines 5.11 kB
/****************************************************************************** * Copyright 2024 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ import { Type, TypeStateListener } from '../graph/type-node.js'; import { TypeReferenceListener, TypeReference } from './type-reference.js'; export interface WaitingForIdentifiableAndCompletedTypeReferencesListener<T extends Type> { onFulfilled(waiter: WaitingForIdentifiableAndCompletedTypeReferences<T>): void; onInvalidated(waiter: WaitingForIdentifiableAndCompletedTypeReferences<T>): void; } /** * The purpose of this class is to inform its listeners, when all given TypeReferences reached their specified initialization state (or a later state). * After that, the listeners might be informed multiple times, * if at least one of the TypeReferences was unresolved/invalid, but later on all TypeReferences are again in the desired state, and so on. */ export declare class WaitingForIdentifiableAndCompletedTypeReferences<T extends Type> implements TypeReferenceListener<T>, TypeStateListener { /** Remembers whether all TypeReferences are in the desired states (true) or not (false). */ protected fulfilled: boolean; /** This is required for cyclic type definitions: * In case of two types A, B which use each other for their properties (e.g. class A {p: B} and class B {p: A}), the case easily occurs, * that the types A and B (respectively their WaitingFor... instances) are waiting for each other and therefore waiting for each other. * In order to solve these cycles, types which are part of such "dependency cycles" should be ignored during waiting, * e.g. A should not waiting B and B should not wait for A. * These types to ignore are stored in the following Set. */ protected typesToIgnoreForCycles: Set<Type>; /** These TypeReferences must be in the states Identifiable or Completed, before the listeners are informed */ protected readonly waitForRefsIdentified: Array<TypeReference<T>> | undefined; /** These TypeReferences must be in the state Completed, before the listeners are informed */ protected readonly waitForRefsCompleted: Array<TypeReference<T>> | undefined; /** These listeners will be informed once, when all TypeReferences are in the desired state. * If some of these TypeReferences are invalid (the listeners will not be informed about this) and later in the desired state again, * the listeners will be informed again, and so on. */ protected readonly listeners: Array<WaitingForIdentifiableAndCompletedTypeReferencesListener<T>>; constructor(waitForRefsToBeIdentified: Array<TypeReference<T>> | undefined, waitForRefsToBeCompleted: Array<TypeReference<T>> | undefined); deconstruct(): void; addListener(newListener: WaitingForIdentifiableAndCompletedTypeReferencesListener<T>, informAboutCurrentState: boolean): void; removeListener(listenerToRemove: WaitingForIdentifiableAndCompletedTypeReferencesListener<T>): void; /** * This method is called to inform about additional types which can be ignored during the waiting/resolving process. * This helps to deal with cycles in type dependencies. * @param moreTypesToIgnore might contain duplicates, which are filtered internally */ addTypesToIgnoreForCycles(moreTypesToIgnore: Set<Type>): void; onTypeReferenceResolved(_reference: TypeReference<T>, resolvedType: Type): void; onTypeReferenceInvalidated(_reference: TypeReference<T>, previousType: Type | undefined): void; onSwitchedToIdentifiable(_type: Type): void; onSwitchedToCompleted(_type: Type): void; onSwitchedToInvalid(_type: Type): void; protected checkIfFulfilled(): void; protected switchToNotFulfilled(): void; isFulfilled(): boolean; } export type WaitingForInvalidTypeReferencesListener<T extends Type> = (waiter: WaitingForInvalidTypeReferences<T>) => void; export declare class WaitingForInvalidTypeReferences<T extends Type> implements TypeReferenceListener<T> { protected counterInvalid: number; protected readonly waitForRefsInvalid: Array<TypeReference<T>>; /** These listeners will be informed, when all TypeReferences are in the desired state. */ protected readonly listeners: Array<WaitingForInvalidTypeReferencesListener<T>>; constructor(waitForRefsToBeInvalid: Array<TypeReference<T>>); deconstruct(): void; addListener(newListener: WaitingForInvalidTypeReferencesListener<T>, informIfAlreadyFulfilled: boolean): void; removeListener(listenerToRemove: WaitingForInvalidTypeReferencesListener<T>): void; onTypeReferenceResolved(_reference: TypeReference<T>, _resolvedType: Type): void; onTypeReferenceInvalidated(_reference: TypeReference<T>, _previousType: Type | undefined): void; isFulfilled(): boolean; getWaitForRefsInvalid(): Array<TypeReference<T>>; } //# sourceMappingURL=type-waiting.d.ts.map