Twitter | Search | |
Sander Elias @🇳🇱
I'm in 😍 with Ivy! ♥♥♥ It finally enabled me to write an custom decorator to make observable life-cycle hooks. No more need of adding placeholder `ngOnxxx` the code below is actually working code. Once ivy is released I will release this too! 🎉🎉🔥🔥🎉🎉
Reply Retweet Like More
little chaosmonster Dec 18
The second thing I am really looking forward to with Ivy is mixins
Reply Retweet Like
Leon Radley Dec 18
Nice! Would it be able to use the OnInit interface instead of the magic strings, inside the decorator?
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Well, true mixins are still a issue. As long as it's next to impossible to tell TS you changed the prototype of anything, its not going. My next 2 will be: 1. `@FromEvent(selector,'click') button$: Observable<event>` 2. `@UnSubOnDestroy() sub = s$.subscribe()`
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Replying to @LeonRadley @angular
Don't know yet. Need to look into that. I preferred magic strings over creating a bunch of decorators for now.
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Replying to @LeonRadley @angular
Did a quick check. the `OnInit` interface has no runtime representation. (the same for the others) That means that I don't see a way to do it now. I'm open for suggestions. If any one has a clue how to pull that off, I'm more as happy to implement.
Reply Retweet Like
Leon Radley Dec 18
I figured as much, since they are interfaces, typescript only uses them at build time. I think the best way would be to have separate decorators for each hook. That way intellisense would help out with completions, and you are faster and less prone to error.
Reply Retweet Like
Leon Radley Dec 18
Having a onDestroy observable would also finally allow us to do this: this.service.getItems$.pipe(takeUntil(this.onDestroy$)) Without the boilerplate :)
Reply Retweet Like
nuton.dev Dec 18
TBH I could live with the hooks, but I would love to have observables of ViewChild events... :)
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Next on my list.
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Replying to @LeonRadley @angular
Also on my list '@unsubOnDestroy'
Reply Retweet Like
nuton.dev Dec 18
😍 And, do you solve the destroy$ pattern for takeUntil? I have seen people using some custom decorators to unsubscribe. But these require to put an empty ngOnDestroy method. How would that go with your observables in place?
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Already works with my current decorator.
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Replying to @LeonRadley @angular
Already works with my decorator.
Reply Retweet Like
Roy Honders Dec 18
Replying to @esosanderelias
what would be the code pre-Ivy?
Reply Retweet Like
nuton.dev Dec 18
Ok :) looking forward to seeing the ViewChildren events :)
Reply Retweet Like
Aslan Vatsaev 🇫🇷 🥨 Dec 18
Is this documented?
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Replying to @avatsaev @angular
No. Ivy isn't ready yet, and my decorator can't be released before that, so there is little use in my documenting it ,😁
Reply Retweet Like
Sander Elias @🇳🇱 Dec 18
Replying to @Retro_IT_NL
Needs to manually add all the lifecycle methods on your class, and create subjects. Next them in every hook
Reply Retweet Like
little chaosmonster Dec 19
Number 1. looks like a kind of solution to the really old hot vs cold observable issue in templates. That issue looked into the same thing on a template level. That said, what I do not like about your approach is that is decoupled from the template. Still very impressive
Reply Retweet Like