First version: 20231229.0.0 (#2)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: Julien Valverdé <julien.valverde@mailo.com> Reviewed-on: https://git.jvalver.de/Thilawyn/thilatrait/pulls/2
This commit was merged in pull request #2.
This commit is contained in:
79
src/tests.ts
79
src/tests.ts
@@ -1,29 +1,62 @@
|
||||
import { mixTraits } from "./trait"
|
||||
import { expresses, trait } from "."
|
||||
|
||||
|
||||
abstract class Identified<ID> {
|
||||
abstract id: ID
|
||||
const Identifiable = <ID>() =>
|
||||
trait(Parent => {
|
||||
abstract class Identifiable extends Parent {
|
||||
abstract readonly id: ID
|
||||
|
||||
equals(el: Identified<ID>) {
|
||||
return this.id === el.id
|
||||
equals(el: Identifiable) {
|
||||
return this.id === el.id
|
||||
}
|
||||
|
||||
constructor(...args: any[]) {
|
||||
super(...args)
|
||||
console.log("Identified constructor")
|
||||
}
|
||||
}
|
||||
|
||||
return Identifiable
|
||||
})
|
||||
|
||||
const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
||||
trait(Parent => {
|
||||
abstract class ImplementsIdentifiable extends Identifiable<ID>()(Parent) {
|
||||
id: ID = defaultID
|
||||
}
|
||||
|
||||
return ImplementsIdentifiable
|
||||
})
|
||||
|
||||
|
||||
const Permissible = trait(Parent => {
|
||||
abstract class Permissible extends Parent {
|
||||
static readonly defaultPermissions: string[] = []
|
||||
permissions: string[] = []
|
||||
|
||||
constructor(...args: any[]) {
|
||||
super(...args)
|
||||
console.log("Permissible constructor")
|
||||
}
|
||||
}
|
||||
|
||||
return Permissible
|
||||
})
|
||||
|
||||
|
||||
const UserProto = expresses(
|
||||
// Identifiable<bigint>(),
|
||||
ImplementsIdentifiable(0n),
|
||||
Permissible,
|
||||
)
|
||||
|
||||
class User extends UserProto {
|
||||
constructor(id: bigint) {
|
||||
super()
|
||||
this.id = id
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ProvideIdentified<ID> extends Identified<ID> {
|
||||
id!: ID
|
||||
}
|
||||
|
||||
abstract class Permissible {
|
||||
protected permissions: string[] = []
|
||||
}
|
||||
|
||||
|
||||
class User extends mixTraits(
|
||||
Identified<bigint>,
|
||||
// Identified<string>,
|
||||
Permissible,
|
||||
) {
|
||||
id: bigint = BigInt(-1)
|
||||
}
|
||||
|
||||
const user = new User()
|
||||
const user1 = new User(1n)
|
||||
console.log(user1)
|
||||
console.log(user1.equals(user1))
|
||||
|
||||
Reference in New Issue
Block a user