Mutable work

This commit is contained in:
Julien Valverdé
2024-06-11 02:53:32 +02:00
parent 61f9baa80f
commit f0a01a3d73
4 changed files with 66 additions and 86 deletions

View File

@@ -1,48 +1,7 @@
import { Schema as S } from "@effect/schema"
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
import type { Mutable } from "effect/Types"
import type { Class, Struct } from "@effect/schema/Schema"
import type { Constructor } from "type-fest"
import type { StaticType } from "../../.."
import type { HasFields, MissingSelfGeneric } from "./util"
export type TMutableClass<
Self,
Fields extends Struct.Fields,
I, R, C,
Inherited,
Proto,
> = (
Constructor<
Omit<
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
keyof Fields
> &
Mutable<Struct.Type<Fields>>,
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
> &
Omit<
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
"extend"
> & {
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
fields: newFields | HasFields<newFields>,
annotations?: Annotations.Schema<Extended>,
) => [Extended] extends [never]
? MissingSelfGeneric<"Base.extend">
: TMutableClass<
Extended,
Fields & newFields,
I & Struct.Encoded<newFields>,
R | Struct.Context<newFields>,
C & Struct.Constructor<newFields>,
Self,
Proto
>
}
)
import type { TMutableClass } from "./TMutableClass"
export function Mutable<
@@ -58,5 +17,21 @@ export function Mutable<
| This
| Class<Self, Fields, I, R, C, Inherited, Proto>
) {
return class_ as (
Constructor<
Omit<
InstanceType<This>,
keyof InstanceType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
> &
InstanceType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>,
ConstructorParameters<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
> &
Omit<
StaticType<This>,
keyof StaticType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
> &
StaticType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
)
}

View File

@@ -1,49 +1,9 @@
import { Schema as S } from "@effect/schema"
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
import type { Mutable } from "effect/Types"
import type { Constructor } from "type-fest"
import type { StaticType } from "../../.."
import type { Annotations, Struct } from "@effect/schema/Schema"
import type { TMutableClass } from "./TMutableClass"
import type { HasFields, MissingSelfGeneric } from "./util"
export type TMutableClass<
Self,
Fields extends Struct.Fields,
I, R, C,
Inherited,
Proto,
> = (
Constructor<
Omit<
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
keyof Fields
> &
Mutable<Struct.Type<Fields>>,
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
> &
Omit<
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
"extend"
> & {
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
fields: newFields | HasFields<newFields>,
annotations?: Annotations.Schema<Extended>,
) => [Extended] extends [never]
? MissingSelfGeneric<"Base.extend">
: TMutableClass<
Extended,
Fields & newFields,
I & Struct.Encoded<newFields>,
R | Struct.Context<newFields>,
C & Struct.Constructor<newFields>,
Self,
Proto
>
}
)
export const MutableClass = <Self = never>(identifier: string) => (
<Fields extends Struct.Fields>(
fieldsOr: Fields | HasFields<Fields>,

View File

@@ -0,0 +1,44 @@
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
import type { Mutable } from "effect/Types"
import type { Constructor } from "type-fest"
import type { StaticType } from "../../.."
import type { HasFields, MissingSelfGeneric } from "./util"
export type TMutableClass<
Self,
Fields extends Struct.Fields,
I, R, C,
Inherited,
Proto,
> = (
Constructor<
Omit<
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
keyof Fields
> &
Mutable<Struct.Type<Fields>>,
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
> &
Omit<
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
"extend"
> & {
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
fields: newFields | HasFields<newFields>,
annotations?: Annotations.Schema<Extended>,
) => [Extended] extends [never]
? MissingSelfGeneric<"Base.extend">
: TMutableClass<
Extended,
Fields & newFields,
I & Struct.Encoded<newFields>,
R | Struct.Context<newFields>,
C & Struct.Constructor<newFields>,
Self,
Proto
>
}
)

View File

@@ -1,3 +1,4 @@
export { MobXObservable } from "./MobXObservable"
export { Mutable } from "./Mutable"
export { MutableClass } from "./MutableClass"
export type { TMutableClass } from "./MutableClass"
export type { TMutableClass } from "./TMutableClass"