2019-03-07 04:33:47 +01:00
|
|
|
export function prop(object: {}, name: string, f: () => any): void {
|
2018-06-05 09:24:47 +02:00
|
|
|
Object.defineProperty(object, name, {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
2019-03-21 16:15:37 +01:00
|
|
|
get(): any {
|
2019-03-07 04:33:47 +01:00
|
|
|
const _value = f.call(this);
|
|
|
|
this[name] = _value;
|
|
|
|
return _value;
|
2018-06-05 09:24:47 +02:00
|
|
|
},
|
2019-03-21 16:15:37 +01:00
|
|
|
set(_value: any): void {
|
2018-06-05 09:24:47 +02:00
|
|
|
Object.defineProperty(this, name, {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
2019-03-07 04:33:47 +01:00
|
|
|
value: _value,
|
2019-03-03 15:07:49 +01:00
|
|
|
writable: true,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2018-06-05 09:24:47 +02:00
|
|
|
}
|
|
|
|
|
2019-03-03 15:07:49 +01:00
|
|
|
export function value<T>(f: () => T): () => T {
|
2019-03-07 04:33:47 +01:00
|
|
|
let _value: T;
|
|
|
|
return (): T => {
|
|
|
|
if (_value !== undefined) return _value;
|
|
|
|
_value = f();
|
|
|
|
return _value;
|
2019-03-03 15:07:49 +01:00
|
|
|
};
|
2018-06-05 09:24:47 +02:00
|
|
|
}
|