Files
ueblueprint/js/entity/ComputedTypeEntity.js
barsdeveloper 365732a99c WIP
2024-12-03 22:15:17 +02:00

29 lines
701 B
JavaScript
Executable File

import IEntity from "./IEntity.js"
import StringEntity from "./StringEntity.js"
export default class ComputedTypeEntity extends IEntity {
static grammar = this.createGrammar()
/** @type {(entity: IEntity) => typeof IEntity} */
static f
static createGrammar() {
return StringEntity.grammar
}
/**
* @template {typeof ComputedTypeEntity.f} T
* @param {T} producer
*/
static from(producer) {
const result = /** @type {(typeof ComputedTypeEntity) & { f: T }} */(this.asUniqueClass())
result.f = producer
return result
}
/** @param {IEntity} entity */
static compute(entity) {
return this.f(entity)
}
}