From f849715a4079836d83d9d6d2f67465f850464eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Wed, 14 Feb 2024 02:04:12 +0100 Subject: [PATCH] TraitBuilder use in tests --- src/TraitBuilder.ts | 2 +- src/tests.ts | 35 ++++++++++++++++------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/TraitBuilder.ts b/src/TraitBuilder.ts index e782495..c40a5fa 100644 --- a/src/TraitBuilder.ts +++ b/src/TraitBuilder.ts @@ -73,7 +73,7 @@ export class TraitBuilder< ) ) => ImplClassWithAbstract ) { - return new Trait( + return new TraitBuilder( this.traitSuperExpression, this.traitAbstract, this.traitStaticAbstract, diff --git a/src/tests.ts b/src/tests.ts index 8f35136..914ef53 100644 --- a/src/tests.ts +++ b/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 -const Identifiable = () => trait( - abstract<{ readonly id: ID }>(), - abstract(), - Super => class Identifiable extends Super { +const Identifiable = () => 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 const ActiveStatefulSubscription = expression