decko
decko copied to clipboard
Is memoize supposed to work on getters?
(tested in Typescript)
import { memoize } from 'decko';
class Stores(){
}
class Container {
@memoize
public get stores () {
return new Stores();
}
}
Throws an error:
Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
For reference: https://github.com/darrylhodgins/typescript-memoize does work.
No, it's not working with getters since decorator method in source code doesn't check if you're applying decorator on regular method or getter:
function decorator(fn) {
return opt => (
typeof opt==='function' ? fn(opt) : (target, key, desc) => {
desc.value = fn(desc.value, opt, target, key, desc);
}
);
}
This would work with getters:
function decorator(fn) {
return opt => (
typeof opt==='function' ? fn(opt) : (target, key, desc) => {
if (desc.value) desc.value = fn(desc.value, opt, target, key, desc);
if (desc.get) desc.get = fn(desc.get, opt, target, key, desc);
}
);
}
PR welcome!