feat(List)
This commit is contained in:
34
src/utils/concept.js
Normal file
34
src/utils/concept.js
Normal file
@ -0,0 +1,34 @@
|
||||
export function satisfiesConcept(obj, pure_virtual, virtual, debug) {
|
||||
if (typeof obj !== 'object' || obj === null) {
|
||||
return false;
|
||||
}
|
||||
if (debug) {
|
||||
const missingMethods = []
|
||||
|
||||
pure_virtual.forEach((method) => {
|
||||
if (typeof obj[method] !== 'function') {
|
||||
missingMethods.push(method)
|
||||
}
|
||||
})
|
||||
|
||||
virtual.forEach((method) => {
|
||||
if (!(method in obj)) {
|
||||
missingMethods.push(method)
|
||||
}
|
||||
})
|
||||
|
||||
if (missingMethods.length !== 0) {
|
||||
console.debug(obj.constructor.name, missingMethods)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if (!pure_virtual.every((method) => typeof obj[method] === 'function')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!virtual.every((method) => method in obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
7
src/utils/mixin.js
Normal file
7
src/utils/mixin.js
Normal file
@ -0,0 +1,7 @@
|
||||
export function mixinClasses(dest, ...sources) {
|
||||
for (const source of sources) {
|
||||
const properties = Object.getOwnPropertyDescriptors(source.prototype)
|
||||
delete properties.constructor
|
||||
Object.defineProperties(dest.prototype, properties)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user