caching simple getters

This commit is contained in:
Yanis Benson 2019-03-27 08:37:25 +03:00
parent 200373790f
commit cbc9f160e8

View file

@ -91,14 +91,18 @@ function Chalk(options) {
for (const [styleName, style] of Object.entries(ansiStyles)) {
styles[styleName] = {
get() {
return createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
Object.defineProperty(this, styleName, {value: builder});
return builder;
}
};
}
styles.visible = {
get() {
return createBuilder(this, this._styler, true);
const builder = createBuilder(this, this._styler, true);
Object.defineProperty(this, 'visible', {value: builder});
return builder;
}
};