TraitBuilder use in tests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julien Valverdé
2024-02-14 02:04:12 +01:00
parent a9181567a2
commit f849715a40
2 changed files with 17 additions and 20 deletions

View File

@@ -73,7 +73,7 @@ export class TraitBuilder<
)
) => ImplClassWithAbstract
) {
return new Trait(
return new TraitBuilder(
this.traitSuperExpression,
this.traitAbstract,
this.traitStaticAbstract,

View File

@@ -1,46 +1,43 @@
import { Trait, trait } from "./Trait"
import { Trait } from "./Trait"
import { trait } from "./TraitBuilder"
import { Implements, ImplementsStatic } from "./TraitExpression"
import { expression } from "./TraitExpressionBuilder"
import { abstract } from "./abstract"
const PrintsHelloOnNew = trait(
abstract(),
abstract(),
Super => class PrintsHelloOnNew extends Super {
const PrintsHelloOnNew = trait
.implement(Super => class PrintsHelloOnNew extends Super {
static readonly isPrintsHelloOnNew = true
constructor(...args: any[]) {
super(...args)
console.log("Hello!")
}
},
)
})
.build()
type PrintsHelloOnNewClass = Trait.Class<typeof PrintsHelloOnNew>
const Identifiable = <ID>() => trait(
abstract<{ readonly id: ID }>(),
abstract(),
Super => class Identifiable extends Super {
const Identifiable = <ID>() => trait
.abstract<{ readonly id: ID }>()
.implement(Super => class Identifiable extends Super {
equals(el: Identifiable) {
return this.id === el.id
}
},
)
})
.build()
const StatefulSubscription = trait(
abstract<{
const StatefulSubscription = trait
.abstract<{
readonly isStatefulSubscription: true
readonly status: (
{ _tag: "awaitingPayment" } |
{ _tag: "active", activeSince: Date, expiresAt?: Date } |
{ _tag: "expired", expiredSince: Date }
)
}>(),
abstract(),
}>()
.build()
Super => class StatefulSubscription extends Super {},
)
type StatefulSubscriptionClass = Trait.Class<typeof StatefulSubscription>
const ActiveStatefulSubscription = expression