Merge branch 'next' of git.valverde.cloud:Thilawyn/thilalib into next
All checks were successful
Lint / lint (push) Successful in 13s
All checks were successful
Lint / lint (push) Successful in 13s
This commit is contained in:
@@ -8,19 +8,19 @@ interface ObservableClassSelf {
|
|||||||
readonly fields: { readonly [K in keyof Schema.Struct.Fields]: Schema.Struct.Fields[K] }
|
readonly fields: { readonly [K in keyof Schema.Struct.Fields]: Schema.Struct.Fields[K] }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ObservableClass = <Self extends ObservableClassSelf>(
|
interface ObservableClassOptions extends Omit<CreateObservableOptions, "proxy"> {}
|
||||||
self: Self,
|
|
||||||
options?: Omit<CreateObservableOptions, "proxy">,
|
|
||||||
) =>
|
|
||||||
class Observable extends self {
|
|
||||||
declare ["constructor"]: typeof Observable
|
|
||||||
|
|
||||||
constructor(...args: any[]) {
|
export const ObservableClass = (options?: ObservableClassOptions) =>
|
||||||
super(...args)
|
<Self extends ObservableClassSelf>(self: Self) =>
|
||||||
|
class Observable extends self {
|
||||||
|
declare ["constructor"]: typeof Observable
|
||||||
|
|
||||||
makeObservable(this,
|
constructor(...args: any[]) {
|
||||||
mapValues(this.constructor.fields, () => observable),
|
super(...args)
|
||||||
options,
|
|
||||||
)
|
makeObservable(this,
|
||||||
}
|
mapValues(this.constructor.fields, () => observable),
|
||||||
} as Self
|
options,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} as Self
|
||||||
|
|||||||
20
src/tests.ts
20
src/tests.ts
@@ -1,5 +1,5 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import { reaction, runInAction } from "mobx"
|
import { computed, makeObservable, reaction, runInAction } from "mobx"
|
||||||
import type { Simplify } from "type-fest"
|
import type { Simplify } from "type-fest"
|
||||||
import { MutableTaggedClass, toJsonifiable } from "./Schema"
|
import { MutableTaggedClass, toJsonifiable } from "./Schema"
|
||||||
import { ObservableClass } from "./Schema/MobX"
|
import { ObservableClass } from "./Schema/MobX"
|
||||||
@@ -18,12 +18,24 @@ type TestB = {
|
|||||||
type Merged = Simplify<ExtendAll<[TestA, TestB]>>
|
type Merged = Simplify<ExtendAll<[TestA, TestB]>>
|
||||||
|
|
||||||
|
|
||||||
class User extends MutableTaggedClass<User>()("User", {
|
|
||||||
|
const UserSchema = MutableTaggedClass<User>()("User", {
|
||||||
id: S.BigIntFromSelf,
|
id: S.BigIntFromSelf,
|
||||||
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
||||||
}).pipe(
|
}).pipe(
|
||||||
ObservableClass
|
ObservableClass()
|
||||||
) {}
|
)
|
||||||
|
|
||||||
|
class User extends UserSchema {
|
||||||
|
constructor(...args: ConstructorParameters<typeof UserSchema>) {
|
||||||
|
super(...args)
|
||||||
|
makeObservable(this, { idAsString: computed })
|
||||||
|
}
|
||||||
|
|
||||||
|
get idAsString() {
|
||||||
|
return this.id.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const JsonifiableUser = User.pipe(
|
const JsonifiableUser = User.pipe(
|
||||||
toJsonifiable(S.Struct({
|
toJsonifiable(S.Struct({
|
||||||
|
|||||||
Reference in New Issue
Block a user