Moved current version to legacy
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
29
src/legacy/observable/makeSchemableClassObservable.ts
Normal file
29
src/legacy/observable/makeSchemableClassObservable.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { mapValues } from "lodash-es"
|
||||
import { makeObservable, observable } from "mobx"
|
||||
import { AbstractConstructor } from "type-fest"
|
||||
import { z } from "zod"
|
||||
import { SchemableClass } from ".."
|
||||
|
||||
|
||||
export function makeSchemableClassObservable<
|
||||
C extends SchemableClass<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, DefaultValues>,
|
||||
|
||||
SchemaT extends z.ZodRawShape,
|
||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
Values extends {},
|
||||
DefaultValues extends Partial<Values>,
|
||||
>(
|
||||
extend: C | SchemableClass<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, DefaultValues>
|
||||
) {
|
||||
return class extends (extend as AbstractConstructor<any>) {
|
||||
constructor(...args: any[]) {
|
||||
super(...args)
|
||||
|
||||
makeObservable(this,
|
||||
mapValues(this.schema.shape, () => observable)
|
||||
)
|
||||
}
|
||||
} as unknown as C
|
||||
}
|
||||
Reference in New Issue
Block a user