Actual use case for JavaScript PROXY!

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 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.

ความคิดเห็น • 28

  • @thatguyintech
    @thatguyintech 26 วันที่ผ่านมา +1

    Really appreciated the progressive code snippets and explanations at each stage. Super useful!

  • @luk318
    @luk318 13 วันที่ผ่านมา

    All other videos I watched about object were like reading wikipedia or witch nonsense examples. Real life examples are always the best. Thank you

  • @SzybkieSzociki
    @SzybkieSzociki 2 หลายเดือนก่อน +1

    First js vido in my life that i actually enjoyd.

  • @DevCoder
    @DevCoder 11 หลายเดือนก่อน

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

  • @TomDoesTech
    @TomDoesTech 2 ปีที่แล้ว +2

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

  • @Jessyco
    @Jessyco 3 หลายเดือนก่อน

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

  • @StefanStefanov-uv2db
    @StefanStefanov-uv2db 7 หลายเดือนก่อน +2

    Very nice tutorial! Definitely an underrated channel..

  • @soumyamondal
    @soumyamondal 4 หลายเดือนก่อน

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

  • @igboanugwocollins4452
    @igboanugwocollins4452 ปีที่แล้ว

    This is super helpful, thank you

  • @williamragstad
    @williamragstad 2 ปีที่แล้ว +1

    Amazing video, you just earned yourself a new subscriber!

  • @THEShAdOwHFV
    @THEShAdOwHFV 5 หลายเดือนก่อน

    Great video, thanks for the info!

  • @TheArmanist
    @TheArmanist 6 หลายเดือนก่อน

    Great explanation, thanks

  • @mayank_m_jain_1160
    @mayank_m_jain_1160 5 หลายเดือนก่อน

    Great Video ! Thanks SIr !

  • @justAbeautifulSoul409
    @justAbeautifulSoul409 หลายเดือนก่อน

    ONE OF THE BESTEXPLANATION
    THABK YOU❤

  • @user-hd7vt8rd7v
    @user-hd7vt8rd7v 9 หลายเดือนก่อน

    Great Vedio, very helpful

  • @AJMichels
    @AJMichels หลายเดือนก่อน

    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.

  • @jmmmmmmmmmk
    @jmmmmmmmmmk 6 หลายเดือนก่อน

    Thx very good video

  • @rotvein4629
    @rotvein4629 6 หลายเดือนก่อน

    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  6 หลายเดือนก่อน +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 11 หลายเดือนก่อน

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

    • @KevinGhadyani
      @KevinGhadyani  11 หลายเดือนก่อน +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 ปีที่แล้ว

    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  ปีที่แล้ว

      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 ปีที่แล้ว +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 ปีที่แล้ว +1

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

    • @KevinGhadyani
      @KevinGhadyani  ปีที่แล้ว

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

    • @animeshkumar9593
      @animeshkumar9593 ปีที่แล้ว +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  ปีที่แล้ว +3

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