import { action , computed , observable } from "mobx" ; import { SaveableSchema } from "./OptionSchemas" ; import { OptionStore } from "./OptionStore" ; export type GetSchemaValue < TSchema > = TSchema extends SaveableSchema < infer U > ? U : never ; template TValue template TSchema export class SaveableStore < TSchema extends SaveableSchema < any > = SaveableSchema < unknown > > extends OptionStore < TSchema > { /**
     * Current state of the value.
     */ @ observable private currentValue = this . schema . getInitialValue ( ) ; /**
     * Gets the current state of the value.
     */ @ computed public get value ( ) : GetSchemaValue < TSchema > { return this . currentValue ; } param newValue @ action public setValue = ( newValue ) : void => { const oldValue = this . currentValue ; this . currentValue = newValue ; this . schema . saveValue ( newValue , oldValue ) ; } ; }