0.1.6 #7

Merged
Thilawyn merged 10 commits from next into master 2024-07-29 18:42:05 +02:00
2 changed files with 5 additions and 78 deletions
Showing only changes of commit 2ad29a147b - Show all commits

View File

@@ -1,63 +0,0 @@
import { Schema } from "@effect/schema"
import type { Types } from "effect"
import type { StaticType } from "../../../StaticType"
import type { HasFields } from "./util"
export interface MutableClass<
Self,
Fields extends Schema.Struct.Fields,
I, R, C,
Inherited,
Proto,
>
extends Omit<
StaticType<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>>,
"extend"
>
{
new(
...args: ConstructorParameters<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>>
): Omit<
InstanceType<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>>,
keyof Fields
> &
Types.Mutable<Schema.Struct.Type<Fields>>
extend<Extended>(identifier: string): <newFields extends Schema.Struct.Fields>(
fields: newFields | HasFields<newFields>,
annotations?: Schema.Annotations.Schema<Extended>,
) => MutableClass<
Extended,
Fields & newFields,
I & Schema.Struct.Encoded<newFields>,
R | Schema.Struct.Context<newFields>,
C & Schema.Struct.Constructor<newFields>,
Self,
Proto
>
}
interface MutableInput<
Self,
Fields extends Schema.Struct.Fields,
I, R, C,
Inherited,
Proto
> extends StaticType<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>> {
new(
props: any,
options?: any,
): Schema.Struct.Type<Fields> & Omit<Inherited, keyof Fields> & Proto
}
export const Mutable = <
Self,
Fields extends Schema.Struct.Fields,
I, R, C,
Inherited,
Proto
>(
self: MutableInput<Self, Fields, I, R, C, Inherited, Proto>
) => self as MutableClass<Self, Fields, I, R, C, Inherited, Proto>

View File

@@ -1,25 +1,15 @@
import { Schema as S } from "@effect/schema"
import { reaction, runInAction } from "mobx"
import { Jsonifiable } from "./Jsonifiable"
import { Class, MobXObservable, MutableTaggedClass, TaggedClass } from "./class"
import { Mutable } from "./class/Mutable"
import { MobXObservable, MutableTaggedClass } from "./class"
// class User extends MutableTaggedClass<User>()("User", {
// id: S.BigIntFromSelf,
// role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
// }).pipe(
// MobXObservable
// ) {}
const UserProto = Class<User>("User")({
class User extends MutableTaggedClass<User>()("User", {
id: S.BigIntFromSelf,
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
})
class User extends UserProto {}
const MutableUser = Mutable(UserProto)
}).pipe(
MobXObservable
) {}
const JsonifiableUser = User.pipe(
Jsonifiable(S.Struct({