import { CombinedEffectResult, EffectOutputSignals } from './effect-signals-factory'; import { ModelInputSignals, ModelWithDefault } from './model-signals-factory'; import { SignalsFactory } from './signals-factory'; import { DerivedId, EffectId, EventId, NoValueType } from './store-utils'; import { ModelValidationResult } from './type-utils'; import { ValidatedInputWithResult, ValidatedInputWithResultOutput } from './validated-input-with-result-signals-factory'; /** * A shallow equals function that performs shallow equals on records or arrays * and else falls back to strict equals. */ export declare const shallowEquals: (a: T, b: T) => boolean; /** * Value-type for the derived model behavior produced by {@link EntityEditFactory} Signals. * * @template Entity - specifies the entity type * @template LoadInput - specifies the input-type for the loading-effect will be `LoadInput | null` (defaults to number) * @template SaveOutput - specifies the output-type for the save-effect (defaults to LoadInput) * @template ValidationFailedType - specifies the type representing a failed validations (total or for a distinct property, hence `ModelValidationResult` will be used as validation result) * @template LoadError - specifies the error type of the load-effect * @template ValidationError - specifies the error type of the validation-effect (use never, if your validation cannot error) * @template SaveError - specifies the error type of the result-effect */ export type EntityEditModel = { /** * The {@link CombinedEffectResult} for the load effect */ load: CombinedEffectResult; /** * The {@link ValidatedInputWithResult} for validation and result effects */ edit: ValidatedInputWithResult, ModelValidationResult, SaveOutput, ValidationError, SaveError>; /** * The current Entity state (matching edit.currentInput.model) * If you need to compare with the current default, use edit.currentInput instead. */ entity: Entity; /** * Current {@link ModelValidationResult} for entity. * If `entity === edit.validatedInput.model` and `isNotEffectError(edit.validationResult)` this matches edit.validationResult, else it's NO_VALUE. */ validation: ModelValidationResult | NoValueType; /** * true, if either: * the load effect is pending, or * the result effect is pending */ loading: boolean; /** * true, if either: * the load effect is pending, or * the result effect is pending, or * the validation effect is pending, or * edit.isValid is false (the current validation result represents invalid entity state, or the validation errored), or * the result-input equals the current-input */ disabled: boolean; /** * true, if the entity does not equal the default entity, with respect to configured * equals function (defaults to {@link shallowEquals}). */ changed: boolean; }; /** * Type specifying the input signals for entity edit signals, hence a combination of * {@link ModelInputSignals}, an id-behavior (load) and a save event. */ export type EntityEditInput = ModelInputSignals & { /** input for the load effect */ load: DerivedId; /** trigger the load effect again, if a model for the current input id was already loaded */ reload: EventId; /** input for the save effect */ save: EventId; }; /** * Type specifying the output signals for entity edit signals, */ export type EntityEditOutput = { /** {@link EffectOutputSignals} for the load effect */ load: EffectOutputSignals; /** {@link ValidatedInputWithResultOutput} for the validation and result effects */ edit: ValidatedInputWithResultOutput, ModelValidationResult, SaveOutput, ValidationError, SaveError>; /** derived bahavior for the {@link EntityEditModel} */ model: DerivedId>; }; /** * Type specifying the configuration for {@link EntityEditFactory}, */ export type EntityEditConfiguration = { /** the initial default entity, hence the initial entity state before the load effect. */ defaultEntity: Entity; /** * Used to determine if the current entity state differs from default. * Note that the default might differ from configured defaultEntity! * A successful load effect will set a new default, as well as dispatching * a setAsDefault event. * This funtion defaults to {@link shallowEquals}, if not specified. */ entityEquals?: (a: Entity, b: Entity) => boolean; /** optional event id for an event that should be dispatched on all save completed events */ onSaveCompletedEvent?: EventId; /** specifies whether the load behavior should be subscribed eagerly (defaults to false) */ eagerLoadSubscription?: boolean; /** if specified with a value `>0`, this will be used as debounce-time for the validation-effect */ validationEffectDebounceTime?: number; }; /** * Type specifying the effects for {@link EntityEditFactory}, */ export type EntityEditEffects = { /** effect that takes an entity-id or null and returns a corresponding entity (which sets the default model) */ load: EffectId; /** effect that takes a {@link ModelWithDefault} for the entity and returns the corresponding {@link ModelValidationResult} */ validation: EffectId, ModelValidationResult, ValidationError>; /** effect that takes an entity and returns the id of the persisted entity */ save: EffectId; }; /** * This type specifies a {@link SignalsFactory} producing signals to load, edit and persist an entity. * * @template Entity - specifies the entity type * @template LoadInput - specifies the input-type for the loading-effect will be `LoadInput | null` (defaults to number) * @template SaveOutput - specifies the output-type for the save-effect (defaults to LoadInput) * @template ValidationFailedType - specifies the type representing a failed validations (total or for a distinct property, hence `ModelValidationResult` will be used as validation result) * @template LoadError - specifies the error type of the load-effect * @template ValidationError - specifies the error type of the validation-effect (use never, if your validation cannot error) * @template SaveError - specifies the error type of the result-effect */ export type EntityEditFactory = SignalsFactory, EntityEditOutput, EntityEditConfiguration, EntityEditEffects>; /** * Generic function to create a specific {@link EntityEditFactory}. * This is another example for factory composition, composing * (a) EffectSignalsFactory for entity loading * (b) ModelSignalsFactory for entity changing * (c) ValidatedInputWithResultSignalsFactory for validation and persiting * * @template Entity - specifies the entity type * @template LoadInput - specifies the input-type for the loading-effect will be `LoadInput | null` (defaults to number) * @template SaveOutput - specifies the output-type for the save-effect (defaults to LoadInput) * @template ValidationFailedType - specifies the type representing a failed validations (total or for a distinct property, hence `ModelValidationResult` will be used as validation result) * @template LoadError - specifies the error type of the load-effect * @template ValidationError - specifies the error type of the validation-effect (use never, if your validation cannot error) * @template SaveError - specifies the error type of the result-effect */ export declare const getEntityEditSignalsFactory: () => EntityEditFactory;