Open johnd0e opened 5 years ago
Currently we already have entities represented as leaflet objects : portal
, link
, field
.
They all are inherited from L.Evented
, and able to fire/process events:
either themselves
(Note: ATM individual portals are not consistestent: #325)
map
object, or any L.FeatureGroup
)
We also need iitc
global object to provide general events.
This object also may become a new base for whole iitc API (instead of polluting window
)
See https://github.com/IITC-CE/ingress-intel-total-conversion/issues/108#issuecomment-509034195
Leaflet event system may be not directly applicable:
try/catch
But as other part of our code also heavily use Leaflet events - perhaps we could to make changes to L.Evented
.
- There is no arguments control, so such errors will not be reported:
Can be fixed in https://github.com/Leaflet/Leaflet/pull/7518
- When firing event - handler call is not wrapped in
try/catch
We need some ideas how to refactor fire
to be able to add try
/catch
there in compatible way.
One more thing that is not supported by Leaflet: interruption of runHooks
:
https://github.com/IITC-CE/ingress-intel-total-conversion/blob/c9d6b98f4cd62b64b1eeea85233fc59f34dcf954/core/code/hooks.js#L67-L81
Well, I'm not sure that it is important, may be we should just discard it. Opinions?
Related commit : 1a8d15d1c59efe4f5ddb7a9d7e1e08e5c06110a1 and https://github.com/IITC-CE/ingress-intel-total-conversion/blob/3cab5faae663eefae3447d87630ddb10bbb86075/plugins/player-activity-tracker.js#L509-L514
Interruption depends on the order of registered hook and doesn't seem used, but the return value of runHooks
is revelant here (true
if any hook returns false
)
@le-jeu I can imagine some use cases for runHooks return value, but I do not see anything relevant in your player-tracker sample
Edit: found single occurrence (in all iitc code): https://github.com/IITC-CE/ingress-intel-total-conversion/blob/3cab5faae663eefae3447d87630ddb10bbb86075/core/code/chat.js#L315-L317
but the return value of
runHooks
is revelant here
So I agree that this may be useful feature (though not essential).
It is possible to simulate it even with current leaflet events, by inspecting data
object after fire
.
And I have some ideas how to improve that in leaflet itself: https://github.com/Leaflet/Leaflet/issues/6787
IITC currently is pretty integrated with Leaflet. And Leaflet event system is powerfull, and definitely more comprehent than IITC custom homebrew hooks.
But then we need some additional compatibility layer to support old plugins.