28
src/effect/schema/tests.ts
Normal file
28
src/effect/schema/tests.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Schema as S } from "@effect/schema"
|
||||
import { pipe } from "effect"
|
||||
import { reaction, runInAction } from "mobx"
|
||||
import { MobXObservable, MutableTaggedClass } from "./class"
|
||||
|
||||
|
||||
class User extends pipe(
|
||||
MutableTaggedClass<User>()("User", {
|
||||
id: S.BigIntFromSelf,
|
||||
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
||||
}),
|
||||
MobXObservable,
|
||||
) {}
|
||||
|
||||
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 })
|
||||
Reference in New Issue
Block a user