Comments (5)
Hi @scaljeri, I am currently on a family vacation. I will take a look as soon as I will return (2 weeks approximately)
from utils-decorators.
Hi @scaljeri, if I understand your intention correctly, you are trying to provide the keyResolver
with some extra data (context).
If you wish to have access to the context you could pass a method name (is more info documentation).
Here is an example (taken from a unit test) https://github.com/vlio20/utils-decorators/blob/master/src/memoize/memoize.spec.ts#L126
from utils-decorators.
Hi @vlio20 In that code example. foo
and fooWithInnerMapper
are both part of the same class. So yes, inside foo
you can probably do what I want (not complete sure). But if you look at my Stackblitz, I would like to create a generic decorator. But maybe I missed the point, so maybe you can modify my stackblitz and demonstrate how to do what I'm looking for.
from utils-decorators.
I have to say that I do not fully understand your proposal. If you want to ignore specific arguments why not just do something like that:
keyResolver: (a: number, b: number, c: numer) => `${a}_${b}`
In this example, I am ignoring a.
from utils-decorators.
In my demo I have the following
import { Cached } from './cache-decorator';
import { CachedParamIgnore } from './cache-param-ignore';
class Example3 {
@Cached({ expirationTimeMs: 4000 })
fibo(@CachedParamIgnore() n: number, x?: number): number {
console.log('calculate for ', n);
if (n < 2) return 1;
return this.fibo(n - 1) + this.fibo(n - 2);
}
}
const test = new Example3();
test.fibo(5, 9));
test.fibo(5, 9));
Inside that Cached
decorator (file) I have that keyResolver function. It doesn't know anything about Example3
or which parameter you want to ignore. Hope this makes more sense :)
from utils-decorators.
Related Issues (20)
- @after method to be provided with the response HOT 6
- move target to es6 HOT 1
- Cache burst for memoize/memoizeAsync HOT 9
- "utils-decorators" has no exported member 'delegatify'. HOT 6
- throttle-async is not functioning as expected HOT 1
- AllDefined decorator
- update dependencies
- Timer, to clear the memory HOT 6
- Disable Caching for test envs HOT 6
- Add support to gettings the method name or expirationTimeMs in cach HOT 9
- [timeout decorator] Should catch the original exception if the method throw an error before timeout HOT 1
- debounce should support multi instances HOT 3
- Update dependencies HOT 1
- Hot cache HOT 3
- Use of mutation testing in utils-decorators - Help needed HOT 2
- update packages
- Leaky bucket (feature request) HOT 6
- missing await on asycMemoyze
- Request for New Feature: Enhancing Decorator Functionality with Queuing Mechanism HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from utils-decorators.