Files
zod-schema-class/src/traits/ObservableZodSchemaObject.ts
Julien Valverdé 1b9fa09186
All checks were successful
continuous-integration/drone/push Build is passing
ObservableZodSchemaObject
2024-02-21 04:45:43 +01:00

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()