TraitBuilder use in tests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -73,7 +73,7 @@ export class TraitBuilder<
|
||||
)
|
||||
) => ImplClassWithAbstract
|
||||
) {
|
||||
return new Trait(
|
||||
return new TraitBuilder(
|
||||
this.traitSuperExpression,
|
||||
this.traitAbstract,
|
||||
this.traitStaticAbstract,
|
||||
|
||||
35
src/tests.ts
35
src/tests.ts
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user