Skip to content

Instantly share code, notes, and snippets.

@danielkcz
Created March 1, 2018 08:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkcz/094f799a1eaa3e2f214941645482a00c to your computer and use it in GitHub Desktop.
Save danielkcz/094f799a1eaa3e2f214941645482a00c to your computer and use it in GitHub Desktop.
Crude typescript defintion for MRF
declare module 'mobx-react-form' {
export default MRF.MobxReactForm
}
type Dictionary<T> = { [key: string]: T }
declare namespace MRF {
class MobxReactForm {
constructor(options: MRF.Options, settings?: MRF.Settings)
isValid: boolean
get(field: string): string
set(obj: Dictionary<string>): void
$(selector: string): Field
onSubmit(): void
init(obj: Dictionary<string>): void
validate(): void
values(): Dictionary<string>
submit<T>(handlers: { onSuccess?: Handler; onError?: Handler }): Promise<T>
errors(): Dictionary<string>
select(path: string): Field
submitting: boolean
}
type Handler = (form: MobxReactForm) => void | Promise<any>
interface Field extends FieldSpec {
bind(): FieldSpec
}
interface FieldSpec {
name?: string
value?: string
label?: string
placeholder?: string
rules?: string
}
type FieldsDefinition = string[] | Dictionary<string | FieldSpec>
interface Options {
fields?: FieldsDefinition
values?: Dictionary<string>
}
interface Settings {
plugins?: {
dvr: any
}
hooks?: {
onSuccess(form: MobxReactForm): void
}
options?: {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment