84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import { Call, ComposeLeft } from "hotscript"
|
|
import { Implements, TraitExpressionAbstractFn, abstract, expression, trait } from "."
|
|
import { SimplifyFn } from "./util"
|
|
|
|
|
|
const PrintsHelloOnNew = trait(
|
|
abstract(),
|
|
Super => class PrintsHelloOnNew extends Super {
|
|
constructor(...args: any[]) {
|
|
super(...args)
|
|
console.log("Hello!")
|
|
}
|
|
},
|
|
)
|
|
|
|
const Identifiable = <ID>() => trait(
|
|
abstract<{ readonly id: ID }>(),
|
|
Super => class Identifiable extends Super {
|
|
equals(el: Identifiable) {
|
|
return this.id === el.id
|
|
}
|
|
},
|
|
)
|
|
|
|
const StatefulSubscription = trait(
|
|
abstract<{
|
|
readonly status: (
|
|
{ _tag: "awaitingPayment" } |
|
|
{ _tag: "active", activeSince: Date, expiresAt?: Date } |
|
|
{ _tag: "expired", expiredSince: Date }
|
|
)
|
|
}>(),
|
|
|
|
Super => class StatefulSubscription extends Super {},
|
|
)
|
|
|
|
// interface ActiveStatefulSubscriptionAbstractMembers extends TraitAbstractMembers<typeof StatefulSubscription> {
|
|
// readonly status: { _tag: "active", activeSince: Date, expiresAt?: Date }
|
|
// }
|
|
|
|
// const ActiveStatefulSubscription = trait(
|
|
// abstract<ActiveStatefulSubscriptionAbstractMembers>(),
|
|
// Super => class ActiveStatefulSubscription extends Super {},
|
|
// )
|
|
|
|
|
|
class TestSuperclass {
|
|
// id: number = 69
|
|
// static test = 69
|
|
}
|
|
|
|
|
|
const builder = expression
|
|
.extends(TestSuperclass)
|
|
.expresses(
|
|
PrintsHelloOnNew,
|
|
Identifiable<bigint>(),
|
|
// Identifiable<number>(),
|
|
StatefulSubscription,
|
|
)
|
|
|
|
const exp = builder.get()
|
|
type Abs = Call<ComposeLeft<[
|
|
TraitExpressionAbstractFn,
|
|
SimplifyFn,
|
|
]>, typeof exp>
|
|
|
|
// exp.subtrait(
|
|
// s => {
|
|
// interface Subtrait extends (typeof s) {
|
|
|
|
// }
|
|
|
|
// return abstract<Subtrait>()
|
|
// },
|
|
// )
|
|
|
|
class User extends exp.extends implements Implements<typeof exp> {
|
|
declare status: { _tag: "awaitingPayment" } | { _tag: "active"; activeSince: Date; expiresAt?: Date | undefined } | { _tag: "expired"; expiredSince: Date }
|
|
id: bigint = -1n
|
|
}
|
|
|
|
console.log(new User())
|