import type { IResettableModel, IValueModel } from '@zajno/common/models/types'; import { Getter } from '@zajno/common/types/getter'; /** * Optimistic model is a observable VM that allows to change its value and then revert it back if the change was not successful. * * To change value, use `value` property setter or `setValue` method. Setter passed to ctor is async by default and should return whether value was changed successfully. * * Before calling setter, the model will change its own value to the new one. * * If the value was not changed successfully, the model will revert the value back to its original value. * * Otherwise, if the result is truthy, the model will keep the new value, but will not read it from the getter. This is helpful is the getter can return incorrect value right after the change. */ export declare class OptimisticModel implements IValueModel, IResettableModel { private readonly getter; private readonly setter; private readonly _model; constructor(getter: Getter, setter: (v: T) => Promise); get originalValue(): T; get value(): T; set value(v: T); private setValue; reset: () => void; }