junderw
6 years ago
No known key found for this signature in database
GPG Key ID: B256185D3A971908
3 changed files with
25 additions and
25 deletions
-
src/payments/lazy.js
-
ts_src/payments/lazy.ts
-
types/payments/lazy.d.ts
|
@ -4,16 +4,16 @@ function prop(object, name, f) { |
|
|
Object.defineProperty(object, name, { |
|
|
Object.defineProperty(object, name, { |
|
|
configurable: true, |
|
|
configurable: true, |
|
|
enumerable: true, |
|
|
enumerable: true, |
|
|
get: function () { |
|
|
get() { |
|
|
let value = f.call(this); |
|
|
const _value = f.call(this); |
|
|
this[name] = value; |
|
|
this[name] = _value; |
|
|
return value; |
|
|
return _value; |
|
|
}, |
|
|
}, |
|
|
set: function (value) { |
|
|
set(_value) { |
|
|
Object.defineProperty(this, name, { |
|
|
Object.defineProperty(this, name, { |
|
|
configurable: true, |
|
|
configurable: true, |
|
|
enumerable: true, |
|
|
enumerable: true, |
|
|
value: value, |
|
|
value: _value, |
|
|
writable: true, |
|
|
writable: true, |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
@ -21,12 +21,12 @@ function prop(object, name, f) { |
|
|
} |
|
|
} |
|
|
exports.prop = prop; |
|
|
exports.prop = prop; |
|
|
function value(f) { |
|
|
function value(f) { |
|
|
let value; |
|
|
let _value; |
|
|
return function () { |
|
|
return () => { |
|
|
if (value !== undefined) |
|
|
if (_value !== undefined) |
|
|
return value; |
|
|
return _value; |
|
|
value = f(); |
|
|
_value = f(); |
|
|
return value; |
|
|
return _value; |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
exports.value = value; |
|
|
exports.value = value; |
|
|
|
@ -1,17 +1,17 @@ |
|
|
export function prop(object: Object, name: string, f: () => any): void { |
|
|
export function prop(object: {}, name: string, f: () => any): void { |
|
|
Object.defineProperty(object, name, { |
|
|
Object.defineProperty(object, name, { |
|
|
configurable: true, |
|
|
configurable: true, |
|
|
enumerable: true, |
|
|
enumerable: true, |
|
|
get: function() { |
|
|
get() { |
|
|
let value = f.call(this); |
|
|
const _value = f.call(this); |
|
|
this[name] = value; |
|
|
this[name] = _value; |
|
|
return value; |
|
|
return _value; |
|
|
}, |
|
|
}, |
|
|
set: function(value) { |
|
|
set(_value) { |
|
|
Object.defineProperty(this, name, { |
|
|
Object.defineProperty(this, name, { |
|
|
configurable: true, |
|
|
configurable: true, |
|
|
enumerable: true, |
|
|
enumerable: true, |
|
|
value: value, |
|
|
value: _value, |
|
|
writable: true, |
|
|
writable: true, |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
@ -19,10 +19,10 @@ export function prop(object: Object, name: string, f: () => any): void { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function value<T>(f: () => T): () => T { |
|
|
export function value<T>(f: () => T): () => T { |
|
|
let value: T; |
|
|
let _value: T; |
|
|
return function(): T { |
|
|
return (): T => { |
|
|
if (value !== undefined) return value; |
|
|
if (_value !== undefined) return _value; |
|
|
value = f(); |
|
|
_value = f(); |
|
|
return value; |
|
|
return _value; |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
@ -1,2 +1,2 @@ |
|
|
export declare function prop(object: Object, name: string, f: () => any): void; |
|
|
export declare function prop(object: {}, name: string, f: () => any): void; |
|
|
export declare function value<T>(f: () => T): () => T; |
|
|
export declare function value<T>(f: () => T): () => T; |
|
|