nyaf icon indicating copy to clipboard operation
nyaf copied to clipboard

Symbol for decorator props

Open joergkrause opened this issue 4 years ago • 2 comments

Use Symbol for decorator props instead of magic strings

joergkrause avatar Sep 08 '20 19:09 joergkrause

Hello,

I don't know if it's a related to my issue, if not please pardon me.

First of all I would like to thank you for all the work you provide in this books, it's amazing. I just reach the chapter about smart selector decorator how to use the power of decorator with dom selection. I followed your example as it is in the book, but unfortunately it did not work for me. here is the code found in the book :

image image image

The propety assigned to the decorator was always undefined.

After few hours of investigation I finally found a solution here it is :

image

I think it's related to the inheritance and how prototype works in javascript. Indeed "this" in the context of the first function was the parent class and not the child so when I run querySelector as getter it could not find the button(#btn).

I don't know if i'm clear. (I'm not a native english speaker)

Anyway thanks again

Yavanha avatar Aug 14 '21 21:08 Yavanha

I tried it and it seems to work. I added it to the book examples here:

https://github.com/joergkrause/webcomponent-book/tree/master/src/examples/chapter9/smart

The type doesn't matter, as it's not relevant and runtime. If the compiler complains, add

"noImplicitThis": false, to tsconfig.json.

joergkrause avatar Aug 24 '21 14:08 joergkrause