Moved old code to legacy/
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:
94
src/tests.ts
94
src/tests.ts
@@ -1,74 +1,62 @@
|
||||
import { AbstractClass } from "type-fest"
|
||||
import { expresses } from "./trait"
|
||||
import { expresses, trait } from "."
|
||||
|
||||
|
||||
function inspectClass(class_: AbstractClass<any, any>) {
|
||||
Object.getOwnPropertyNames(class_).forEach(name => {
|
||||
console.log(
|
||||
"[static]",
|
||||
name,
|
||||
Object.getOwnPropertyDescriptor(class_, name)
|
||||
)
|
||||
const Identifiable = <ID>() =>
|
||||
trait(Parent => {
|
||||
abstract class Identified extends Parent {
|
||||
abstract id: ID
|
||||
|
||||
equals(el: Identified) {
|
||||
return this.id === el.id
|
||||
}
|
||||
|
||||
constructor(...args: any[]) {
|
||||
super(...args)
|
||||
console.log("Identified constructor")
|
||||
}
|
||||
}
|
||||
|
||||
return Identified
|
||||
})
|
||||
|
||||
Object.getOwnPropertyNames(class_.prototype).forEach(name => {
|
||||
console.log(
|
||||
"[prototype]",
|
||||
name,
|
||||
Object.getOwnPropertyDescriptor(class_.prototype, name)
|
||||
)
|
||||
const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
||||
trait(Parent => {
|
||||
abstract class ImplementsIdentifiable extends Identifiable<ID>()(Parent) {
|
||||
id: ID = defaultID
|
||||
}
|
||||
|
||||
return ImplementsIdentifiable
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
abstract class Identified<ID> {
|
||||
abstract id: ID
|
||||
const Permissible = trait(Parent => {
|
||||
abstract class Permissible extends Parent {
|
||||
static readonly defaultPermissions: string[] = []
|
||||
permissions: string[] = []
|
||||
|
||||
equals(el: Identified<ID>) {
|
||||
return this.id === el.id
|
||||
constructor(...args: any[]) {
|
||||
super(...args)
|
||||
console.log("Permissible constructor")
|
||||
}
|
||||
}
|
||||
|
||||
// initializer() {
|
||||
// console.log("Identified initializer")
|
||||
// }
|
||||
}
|
||||
|
||||
class ImplementsIdentifiable<ID> extends Identified<ID> {
|
||||
id!: ID
|
||||
}
|
||||
return Permissible
|
||||
})
|
||||
|
||||
|
||||
abstract class Permissible {
|
||||
static readonly defaultPermissions: string[] = []
|
||||
permissions: string[] = []
|
||||
// permissions!: string[]
|
||||
|
||||
constructor() {
|
||||
console.log("Permissible constructor")
|
||||
}
|
||||
|
||||
initializer() {
|
||||
console.log("Permissible initializer")
|
||||
this.permissions = []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class User extends expresses(
|
||||
Identified as typeof Identified<bigint>,
|
||||
// Identified<string>,
|
||||
const UserProto = expresses(
|
||||
// Identifiable<bigint>(),
|
||||
ImplementsIdentifiable(0n),
|
||||
Permissible,
|
||||
) {
|
||||
readonly id: bigint
|
||||
)
|
||||
|
||||
class User extends UserProto {
|
||||
constructor(id: bigint) {
|
||||
super()
|
||||
this.id = id
|
||||
}
|
||||
}
|
||||
|
||||
const user1 = new User(BigInt(1))
|
||||
const user2 = new User(BigInt(2))
|
||||
|
||||
const user1 = new User(1n)
|
||||
console.log(user1)
|
||||
console.log(user1.equals(user2))
|
||||
console.log(user1.equals(user1))
|
||||
|
||||
Reference in New Issue
Block a user