nyaf
nyaf copied to clipboard
Symbol for decorator props
Use Symbol for decorator props instead of magic strings
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 :
The propety assigned to the decorator was always undefined.
After few hours of investigation I finally found a solution here it is :
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
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.