stevage / map-gl-utils

A utility library that makes Mapbox GL JS or Maplibre GL a bit more convenient to work with.
https://npmjs.com/package/map-gl-utils
212 stars 24 forks source link

Add return with "disable" function #12

Closed MateusLehmkuhl closed 4 years ago

MateusLehmkuhl commented 4 years ago

In functions where is added a listener to map, added a function in return what i can use to disable this listeners.

MateusLehmkuhl commented 4 years ago

Well, I agree with your statements, I had done it in the first instance in this second way that you suggested, (including in my first commit). Really, the ideal would be the two suggested implementations, I can go on working on that. You can then look at what I did on my first commit and then I revert my MR to him (https://github.com/stevage/mapbox-gl-utils/pull/12/commits/803f1b0f858eaa231617c9da34dcc70692957ef8).

MateusLehmkuhl commented 4 years ago

I did it this way because it follows the React Hooks standards, e.g.:

  useEffect (() => {
     ChatAPI.subscribeToFriendStatus (friendID, handleStatusChange);
     return () => {
       ChatAPI.unsubscribeFromFriendStatus (friendID, handleStatusChange);
     };
   });
stevage commented 4 years ago

Thanks. After a bit more thought I think you're right - this way is better. I hadn't come across this pattern before.