rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
319 stars 102 forks source link

Added support for AddListenerOnce and refactor to single EventEntityBase #259

Closed Nickztar closed 1 year ago

Nickztar commented 1 year ago

This adds the ability to only have a event listen once and then never trigger again. Useful for when you want to do something like fixing zoom after idle but not triggering on every idle.

Not sure about which is the best standard to use for eventListeners since it's somewhat different across the project. As you can see in this https://github.com/rungwiroon/BlazorGoogleMaps/blob/89e8239ac05cf9c230eaf12e958995542163741f/GoogleMapsComponents/Maps/ListableEntityBase.cs#L61 we prevent duplicates, but not in all the places. Added a note in my new base class for the possibility of this. Could be configured per entity type aswell but for now I left those untouched.

valentasm1 commented 1 year ago

I am on vacations in Malta till Sunday. Guarantied will merge after that but maybe even before that day.

Nickztar commented 1 year ago

No stress, might change some things until then! Enjoy the vacation :D

valentasm1 commented 1 year ago

My rule of thumb if you need to change smth you need to change in one place. Thats why i made Dispose virtual and put there _jsObjectRef.Dispose(); in EventEntityBase. Except in one component i need to ovveride it and call base explicitly.

Second thing. Not calling base.Dispose() in GoogleMap.razor. It throws null reference error on page reload in MapComponent first time and second time it just pass object which is disposed. Probalby it is smth asp.net lifecycle flow. Just made InteropObject?.Dispose(); and wont try to inverstigate why. Just keep that in mind :).

Also moved protected readonly JsObjectRef _jsObjectRef; to EventEntityBase and couple minor refactor.

Thank you for help. You get invisible karma points :).

Nickztar commented 1 year ago

Welcome back from the vacation. Hope you had a good time!

Your change is great, not sure why I didn't consider moving it into the base class.