21 lines
674 B
TypeScript
21 lines
674 B
TypeScript
import { trait } from "@thilawyn/traitify-ts"
|
|
import { mapValues } from "lodash-es"
|
|
import { makeObservable, observable } from "mobx"
|
|
import { z } from "zod"
|
|
|
|
|
|
export const ObservableZodSchemaObject = trait
|
|
.staticAbstract(Super => class extends Super {
|
|
declare readonly schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, object, object>
|
|
})
|
|
.implement(Super => class ObservableZodSchemaObject extends Super {
|
|
constructor(...args: any[]) {
|
|
super(...args)
|
|
|
|
makeObservable(this,
|
|
mapValues(ObservableZodSchemaObject.schema.shape, () => observable)
|
|
)
|
|
}
|
|
})
|
|
.build()
|