/** * [[include:core/decorators/cache/README.md]] * @packageDocumentation * @module decorators/cache */ import { error } from 'jodit/core/helpers'; import type { IDictionary } from 'jodit/types'; export interface CachePropertyDescriptor extends PropertyDescriptor { get?: (this: T) => R; } export function cache( target: object, name: PropertyKey, descriptor: CachePropertyDescriptor ): void { const getter = descriptor.get; if (!getter) { throw error('Getter property descriptor expected'); } descriptor.get = function (this: T): R { const value = getter.call(this); if (value && (value as IDictionary).noCache === true) { return value; } Object.defineProperty(this, name, { configurable: descriptor.configurable, enumerable: descriptor.enumerable, writable: false, value }); return value; }; }