Trait refactoring
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julien Valverdé
2024-02-03 02:18:36 +01:00
parent 3c40a0a96b
commit c1097ff2f2
3 changed files with 43 additions and 33 deletions

View File

@@ -1,41 +1,44 @@
import { Implements, TraitAbstractMembers, expression, trait } from "."
import { Implements, TraitAbstractMembers, abstract, expression, trait } from "."
const PrintsHelloOnNew = trait()(Super =>
class PrintsHelloOnNew extends Super {
const PrintsHelloOnNew = trait(
abstract(),
Super => class PrintsHelloOnNew extends Super {
constructor(...args: any[]) {
super(...args)
console.log("Hello!")
}
}
},
)
const Identifiable = <ID>() => (
trait<{ readonly id: ID }>()(Super =>
class Identifiable extends Super {
equals(el: Identifiable) {
return this.id === el.id
}
const Identifiable = <ID>() => trait(
abstract<{ readonly id: ID }>(),
Super => class Identifiable extends Super {
equals(el: Identifiable) {
return this.id === el.id
}
)
},
)
const StatefulSubscription = trait<{
readonly status: (
{ _tag: "awaitingPayment" } |
{ _tag: "active", activeSince: Date, expiresAt?: Date } |
{ _tag: "expired", expiredSince: Date }
)
}>()(Super =>
class StatefulSubscription extends Super {}
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<ActiveStatefulSubscriptionAbstractMembers>()(Super =>
class ActiveStatefulSubscription extends Super {}
const ActiveStatefulSubscription = trait(
abstract<ActiveStatefulSubscriptionAbstractMembers>(),
Super => class ActiveStatefulSubscription extends Super {},
)