/*! * Jodit Editor (https://xdsoft.net/jodit/) * Released under MIT see LICENSE.txt in the project root for license information. * Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net */ import { error } from '../helpers'; export interface CachePropertyDescriptor extends PropertyDescriptor { get?: (this: T) => R; } export function cache( _target: any, name: PropertyKey, descriptor: CachePropertyDescriptor ): void { const getter = descriptor.get; if (!getter) { throw error('Getter property descriptor expected'); } descriptor.get = function (this: T) { const value = getter.call(this); Object.defineProperty(this, name, { configurable: descriptor.configurable, enumerable: descriptor.enumerable, writable: false, value }); return value; }; }