Files
thilalib/src/tests.ts
Julien Valverdé c0433a8c76
All checks were successful
Publish / publish (push) Successful in 15s
Lint / lint (push) Successful in 11s
0.1.12 (#13)
Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: #13
2024-08-20 23:44:13 +02:00

50 lines
1.1 KiB
TypeScript

import { Schema as S } from "@effect/schema"
import { reaction, runInAction } from "mobx"
import type { Simplify } from "type-fest"
import { MutableTaggedClass, toJsonifiable } from "./Schema"
import { ObservableClass } from "./Schema/MobX"
import type { ExtendAll } from "./Types"
type TestA = {
heugneu: string
type: "Type1" | "Type2"
}
type TestB = {
type: "Type1"
}
type Merged = Simplify<ExtendAll<[TestA, TestB]>>
class User extends MutableTaggedClass<User>()("User", {
id: S.BigIntFromSelf,
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
}).pipe(
ObservableClass
) {}
const JsonifiableUser = User.pipe(
toJsonifiable(S.Struct({
...User.fields,
id: S.BigInt,
}))
)
const user1 = new User({ id: -1n, role: "BasicUser" })
reaction(() => user1.id, id => console.log(`user1 id changed: ${ id }`))
class Admin extends User.extend<Admin>("Admin")({
// role: S.Literal("Admin")
}) {}
const user2 = new Admin({ id: -1n, role: "Admin" })
reaction(() => user2.id, id => console.log(`user2 id changed: ${ id }`))
runInAction(() => { user1.id = 1n })
runInAction(() => { user2.id = 2n })