UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

49 lines (46 loc) 1.7 kB
import { isValid } from "@visactor/vutils"; import { createID } from "../util/id"; import { CompilableBase } from "./compilable-base"; export class GrammarItem extends CompilableBase { constructor() { super(...arguments), this.id = createID(), this._compiledProductId = null, this._depend = []; } getProduct() { if (isValid(this._product)) return this._product; const view = this.getVGrammarView(), id = this.getProductId(); return isValid(id) && isValid(view) && (this._product = this._lookupGrammar(id)), this._product; } getProductId() { var _a; return null !== (_a = this._compiledProductId) && void 0 !== _a ? _a : this.generateProductId(); } getDepend() { return this._depend; } setDepend(...depend) { this._depend = depend; } compile(option) { this._compileProduct(option), this._afterCompile(option); } _afterCompile(option) { var _a; isValid(this._product) && (null === (_a = this.getCompiler()) || void 0 === _a || _a.addGrammarItem(this)); } updateDepend() { if (isValid(this._product)) { const depend = this.getDepend().map((item => item.getProduct())).filter(isValid); return this._product.depend(depend), depend.length === this.getDepend().length; } return !1; } release() { this.removeProduct(), super.release(), this._depend = []; } removeProduct(reserveVGrammarModel) { this.getCompiler().removeGrammarItem(this, reserveVGrammarModel), this._product = null, this._compiledProductId = null; } } //# sourceMappingURL=grammar-item.js.map