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