jodit
Version:
Jodit is awesome and usefully wysiwyg editor with filebrowser
37 lines (29 loc) • 834 B
text/typescript
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2020 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
import { error } from '../helpers';
export interface CachePropertyDescriptor<T, R> extends PropertyDescriptor {
get?: (this: T) => R;
}
export function cache<T, R>(
target: any,
name: PropertyKey,
descriptor: CachePropertyDescriptor<T, R>
): 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;
};
}