mgechev / memo-decorator Goto Github PK
View Code? Open in Web Editor NEWDecorator which applies memoization to a method of a class.
Decorator which applies memoization to a method of a class.
It would be great to support ng-add command for Angular.
ng add memo-decorator
The @angular/cli suggest the following:
The package that you are trying to add does not support schematics. You can try using a different version of the package or contact the package author to add ng-add support.
We generally use the following syntax for our angular classes:
class foo {
bar = () =>{
return 'foo'
}
}
is there a way to use the memo decorator in methods declared like this? Currently, it throws an error if I just put it before the method declaration.
I have an NX workspace setup and I have been using memo-decorator for quite a bit now.
I have libraries that use memo-decorator, and applications that use those libs. Everything works perfect inside my NX workspace.
But when I am trying to publish my library to npm and then import it in an external project.
I am getting the following errors.
[Error] TypeError: memo_decorator__WEBPACK_IMPORTED_MODULE_1__ is not a function. (In 'memo_decorator__WEBPACK_IMPORTED_MODULE_1__()', 'memo_decorator__WEBPACK_IMPORTED_MODULE_1__' is an instance of Object)
(anonymous function) (vendor.js:119720:96)
__webpack_require__ (runtime.js:23)
(anonymous function) (vendor.js:116631:103)
__webpack_require__ (runtime.js:23)
(anonymous function) (vendor.js:116822:116)
__webpack_require__ (runtime.js:23)
(anonymous function) (vendor.js:117104:106)
__webpack_require__ (runtime.js:23)
(anonymous function) (vendor.js:115324:109)
__webpack_require__ (runtime.js:23)
(anonymous function) (main.js:70:93)
__webpack_require__ (runtime.js:23)
(anonymous function) (main.js:389:93)
__webpack_require__ (runtime.js:23)
(anonymous function) (runtime.js:57)
(anonymous function) (main.js:664)
webpackJsonpCallback (runtime.js:316)
webpackJsonpCallback
Module Code (main.js:1:84)
evaluate
moduleEvaluation
(anonymous function)
promiseReactionJob
Hi!
Is there any way to clean the values memorized by the library? When is it cleaning them?
If I have several pages with thousands of rows in tables this can occupy a lot of memory. Isn't that a thing I should be worried about?
Thanks!
There are several PRs for updating dependencies, which are almost 1 year old. Is this repository still maintained? :)
edit: Btw very nice presentation in 2018 on ng-conf ("Optimizing an Angular application"), just realized it was you who presented and and mentioned your own npm package =)
I just figured out the hard way that by default the resolver only uses the first argument passes to the function as map cache key (lodash.memorize).
This should be mentioned somewhere and may be even provide a more in depth explanation of how to write your own resolver.
Hello. Just watched your talk on ngconf and I wanted to see what is happening behind the scenes in this package.
I noticed that you are using lodash.memoize
and immediately remembered this tweet:
https://twitter.com/dtinth/status/987533473064742912
Maybe it would be better to switch to other memozing library. First one that comes in mind is https://github.com/planttheidea/moize
When IE11 tries to load this package, it throws an error "Syntax error". In a debug version of an Angular application, this occurs at:
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst memoize = __webpack_require__(\"../../../../lodash.memoize/index.js\");\nexports.default = (resolver) => (target, key, descriptor) => {\n if (typeof descriptor.value !== 'function') {\n throw new Error('Memoization can be applied only to methods');\n }\n descriptor.value = memoize(descriptor.value, resolver);\n return descriptor;\n};\n//# sourceMappingURL=index.js.map//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkM6L0dpdC9EaXJlY3RvcnlTZXJ2aWNlL1VJL3BpLWRpcmVjdG9yeS9ub2RlX21vZHVsZXMvbWVtby1kZWNvcmF0b3IvaW5kZXguanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUFDQSw4Q0FBOEMsY0FBYztBQUM1RDtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiLi4vLi4vLi4vLi4vbWVtby1kZWNvcmF0b3IvaW5kZXguanMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcbk9iamVjdC5kZWZpbmVQcm9wZXJ0eShleHBvcnRzLCBcIl9fZXNNb2R1bGVcIiwgeyB2YWx1ZTogdHJ1ZSB9KTtcbmNvbnN0IG1lbW9pemUgPSByZXF1aXJlKCdsb2Rhc2gubWVtb2l6ZScpO1xuZXhwb3J0cy5kZWZhdWx0ID0gKHJlc29sdmVyKSA9PiAodGFyZ2V0LCBrZXksIGRlc2NyaXB0b3IpID0+IHtcbiAgICBpZiAodHlwZW9mIGRlc2NyaXB0b3IudmFsdWUgIT09ICdmdW5jdGlvbicpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdNZW1vaXphdGlvbiBjYW4gYmUgYXBwbGllZCBvbmx5IHRvIG1ldGhvZHMnKTtcbiAgICB9XG4gICAgZGVzY3JpcHRvci52YWx1ZSA9IG1lbW9pemUoZGVzY3JpcHRvci52YWx1ZSwgcmVzb2x2ZXIpO1xuICAgIHJldHVybiBkZXNjcmlwdG9yO1xufTtcbi8vIyBzb3VyY2VNYXBwaW5nVVJMPWluZGV4LmpzLm1hcFxuXG5cbi8vLy8vLy8vLy8vLy8vLy8vL1xuLy8gV0VCUEFDSyBGT09URVJcbi8vIEM6L0dpdC9EaXJlY3RvcnlTZXJ2aWNlL1VJL3BpLWRpcmVjdG9yeS9ub2RlX21vZHVsZXMvbWVtby1kZWNvcmF0b3IvaW5kZXguanNcbi8vIG1vZHVsZSBpZCA9IC4uLy4uLy4uLy4uL21lbW8tZGVjb3JhdG9yL2luZGV4LmpzXG4vLyBtb2R1bGUgY2h1bmtzID0gdmVuZG9yIl0sInNvdXJjZVJvb3QiOiJ3ZWJwYWNrOi8vLyJ9\n//# sourceURL=webpack-internal:///../../../../memo-decorator/index.js\n");
Running this in the console in IE resulted in the same error.
I may be missing a polyfill, but it's unclear to me what I'm missing.
Memoized method is bound to prototype, but not to instance as expected.
class S {
run = false;
@memo() go() {
this.run = true;
}
}
it('should mark as run after go', () => {
const s1 = new S();
s1.go();
expect(s1.run).toEqual(true); // ok
});
it('should also mark as run after go', () => {
const s2 = new S();
s2.go();
expect(s2.run).toEqual(true); // Expected false to equal true.
});
it('should not mark as run without go', () => {
const s3 = new S();
// skipping s3.go();
expect(s3.run).toEqual(false); // ok
});
In my application in the production code this is not a problem, but it ruins the tests.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.