Actual use case for JavaScript PROXY!

Sdílet
Vložit
  • čas přidán 21. 09. 2021
  • Use cases for JavaScript proxies is one of the things most people aren't familiar with doing, but it's a super powerful tool if you know how to use them.
    I show you a way I'm using proxies today at work for deprecating object properties that aren't functions.

Komentáře • 26

  • @SzybkieSzociki
    @SzybkieSzociki Před měsícem +1

    First js vido in my life that i actually enjoyd.

  • @StefanStefanov-uv2db
    @StefanStefanov-uv2db Před 6 měsíci +2

    Very nice tutorial! Definitely an underrated channel..

  • @TomDoesTech
    @TomDoesTech Před 2 lety +2

    Great video! I've found of a use-case for proxies before, but this seems really useful.

  • @DevCoder
    @DevCoder Před 10 měsíci

    Awesome video Kevin! It is a very helpful use-case. Thank you so much for this

  • @justAbeautifulSoul409

    ONE OF THE BESTEXPLANATION
    THABK YOU❤

  • @williamragstad
    @williamragstad Před 2 lety +1

    Amazing video, you just earned yourself a new subscriber!

  • @igboanugwocollins4452

    This is super helpful, thank you

  • @Jessyco
    @Jessyco Před 2 měsíci

    This was a great example and use case, thank you!

  • @soumyamondal
    @soumyamondal Před 3 měsíci

    I'll definitely share this one, truly amazing content.

  • @TheArmanist
    @TheArmanist Před 5 měsíci

    Great explanation, thanks

  • @THEShAdOwHFV
    @THEShAdOwHFV Před 4 měsíci

    Great video, thanks for the info!

  • @mayank_m_jain_1160
    @mayank_m_jain_1160 Před 4 měsíci

    Great Video ! Thanks SIr !

  • @AJMichels
    @AJMichels Před 15 dny

    Nice video.
    It is inaccurate to say the original commits are “deleted” when performing a rebase. They still exist and can be accessed and even recovered if you know their original hashes. They do end up in an orphaned state and can be “cleaned up” under certain circumstances in the future.

  • @user-hd7vt8rd7v
    @user-hd7vt8rd7v Před 8 měsíci

    Great Vedio, very helpful

  • @jmmmmmmmmmk
    @jmmmmmmmmmk Před 5 měsíci

    Thx very good video

  • @rotvein4629
    @rotvein4629 Před 5 měsíci

    For me it seems more obvious and simple just to add to the `fontSized` object a property `__proto__: legacyFontSizes`. Then `extreaLagre` and `extraSmall` won't appear by iteration, but not break the legacy code as e.g. with an attempt of getting `extraSmall` the `gigantic` will be returned.
    I still find your video very clear-cut and helpful, thank you!
    But can you please answer if in this particular case my solution is inferior to the approach with `Proxy`?

    • @KevinGhadyani
      @KevinGhadyani  Před 5 měsíci +1

      That's a great idea and a lot simpler! Personally, I wouldn't depend on proto as that's like black magic; unless I'm missing the mark. It's got that code smell. You also need to check for existing values first too. Hmm 🤔.

  • @mgrycz
    @mgrycz Před 10 měsíci

    Can I ask what font do you use in the video?

    • @KevinGhadyani
      @KevinGhadyani  Před 10 měsíci +1

      For the code of thumbnail? The code is Victor Mono, but I'm not exactly sure what it was in this video.

  • @lborate3543
    @lborate3543 Před rokem

    You can literally just set the forntsizes extralarge to the new translation. The proxy isnt doing anything magical.
    FontSizes.ExtraLarge.Value
    When you have to update your code for depricated values you can just set the value from the object. What is it that a proxy can do that cant be done in a simple return value or if then statements?

    • @KevinGhadyani
      @KevinGhadyani  Před rokem

      If people are using your library, but you have an object and not a function, this is a way of adding code to an object that isn't a function.
      Most times, you don't want breaking changes in a library, and proxies can make these changes non-breaking.

    • @lborate3543
      @lborate3543 Před rokem +1

      @Kevin Ghadyani - JavaScript oh you're using it inside a library. I was thinking this was all inside the same class. I guess if it's in a library then it probably is more useful as the Contractor is created for 100's of users.

  • @injSrc
    @injSrc Před rokem +1

    Why we can't do something like
    const FontSize = {
    .......
    tiny: tiny,
    get extraSmall() {
    console.warn('warning...')
    return this.tiny
    }
    .......
    }

    • @KevinGhadyani
      @KevinGhadyani  Před rokem

      Does that work? I've only ever done that with proxies and Object.defineProperty.

    • @animeshkumar9593
      @animeshkumar9593 Před rokem +2

      I feel this should work, but with these caveats:
      1. The more the number of deprecated keys, the larger the object grows as you need to define getters/setters for all the deprecated keys. Proxy does it in one place.
      2. Object.keys(FontSize) would still return the deprecated keys. While you can mark the deprecated keys as non-enumerable, you would need to do that for each and every key.

    • @KevinGhadyani
      @KevinGhadyani  Před rokem +3

      I had a live stream where I converted object-based to proxies, and it's like you said, proxies scale better.