Host decorators are dead... use host element binding instead

Поділитися
Вставка
  • Опубліковано 7 лис 2024

КОМЕНТАРІ • 13

  • @jandrorojas6714
    @jandrorojas6714 22 години тому +1

    That looks super cool and clean, but it needs better integration with IDEs... private members used exclusively for host bindings/listeners will be marked as "unused"

  • @IhorKalchenko
    @IhorKalchenko Місяць тому

    Thanks for nice examples, I'll keep it in mind 🤝

  • @crebuh
    @crebuh 3 місяці тому

    Great explanation! After watching this, I immediately changed all my event emitters to the new output function. Thanks Brian!

  • @Ruslan4ic
    @Ruslan4ic Місяць тому +1

    Nice example, what about to don't use effect practice?

    • @briantreese
      @briantreese  Місяць тому +1

      Good question.
      For the effect() function, I think the concept is: don't use it unless you need to, and avoid over using it. But there are reasons to use it.
      One of the use cases from the official docs is "Adding custom DOM behavior that can't be expressed with template syntax", which would be the category that our example falls under in this case.
      Hope that helps

  • @LeungWong
    @LeungWong 3 місяці тому +3

    I hope they will improve the typing for "host". right now for instance it is possible to give any name for the click event function and it still would build.

  • @sinthoras91
    @sinthoras91 3 місяці тому +1

    Great we moved everything from host to hostbinding decorator and now we should move it back again? Thats how we can keep stay busy right?

  • @IgorPak-b5n
    @IgorPak-b5n Місяць тому

    but what about type safety?

    • @briantreese
      @briantreese  Місяць тому

      Yep, that's one of the downsides to the way that this has changed. Hopefully tooling will get better around this in the near future.

  • @paschalokafor9043
    @paschalokafor9043 4 місяці тому

    Do you still need renderer when using host binding?

    • @briantreese
      @briantreese  4 місяці тому +1

      I this case I do since I’m using the addClass() and removeClass() methods to toggle a class on the body element. If I were only binding the class on the host element then I wouldn’t need it.
      But, just to be clear, this is only for the example in this video. Binding a class on the host element does not require the renderer.
      Hope that helps.

    • @paschalokafor9043
      @paschalokafor9043 4 місяці тому +1

      @@briantreese Wow. Very clear. Thank you. I tried using it but it throws an error about not having a provider. I am using standalone components