Git Product home page Git Product logo

Comments (5)

vlio20 avatar vlio20 commented on August 10, 2024 2

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.

vlio20 avatar vlio20 commented on August 10, 2024

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.

scaljeri avatar scaljeri commented on August 10, 2024

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.

vlio20 avatar vlio20 commented on August 10, 2024

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.

scaljeri avatar scaljeri commented on August 10, 2024

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));

file

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.