fix(core): initialize services earlier to ensure the map has been created for plugins#364
fix(core): initialize services earlier to ensure the map has been created for plugins#364
Conversation
…ated for plugins The map may not have been initialized if the services weren't fully received from a remote source when a plugin has been added.
There was a problem hiding this comment.
🏓 @dopenguin
🏓 @oeninghe-dataport I made a comment requesting your feedback, too.
M-M-M-MULTIBALL.
| const overlay = useTemplateRef<typeof PolarMapOverlay>('polar-map-overlay') | ||
|
|
||
| let map: Map | null = null | ||
| let map: Map = {} as Map |
There was a problem hiding this comment.
@oeninghe-dataport This is a workaround to avoid null checks later on in all plugins. It is assumed and/or planned that, before anything else gets their turn, createMap is run and completed. So effectively, nothing will ever run into an uninitialized map, except for the first call to createMap itself.
It still is an object rather than a real new Map() so errors regarding this are more apparent. What's your feedback on this?
| const map = useTemplateRef('map') | ||
|
|
||
| createMap( | ||
| await createMap( |
There was a problem hiding this comment.
I am having trouble imagining how this works. I've checked the code in the snowbox, too, and apparently createMap and addPlugin calls can be made fully independant of each other. This is especially troubling me since I do not understand in which map the added plugin will end up in, and how to control and direct that behaviour.
I'd have expected a return value to createMap that is required to either run addPlugin with as a parameter, or that addPlugin is registered on, id est:
const polarInstance = await createMap()
// addPlugin on instance
polarInstanceaddPlugin(...)
// XOR addPlugin requires instance as parameter
addPlugin(polarInstance, ...)The way it is currently written, I could just
createMap()
addPlugin()
addPlugin()
addPlugin()
createMap()
addPlugin()
without await (since nothing is actively forcing me to await except for the following errors, if they occur ...) and be none the wiser what I have actually done. (I also tried to just randomly call addPlugin before createMap, but that fails internally due to pinia not being initialized.)
Maybe I'm missing the idea here?
There was a problem hiding this comment.
In the state of this branch, all plugins are added to the same store. createMap effectively works on the same store. #356 tackles that.
However, your expectation seems to go a way that seems valid, even though it is a doubled effort.
There was a problem hiding this comment.
@oeninghe-dataport Due to the possibly duplicate effort I'd like your take on this detail, too. If this is already handled, we may as well close this thread. May need a ☎️ to resolve this quickly.
There was a problem hiding this comment.
@warm-coolguy I think your expectation is handled in #356 ; have a look at
polar/examples/snowbox/index.js
Line 63 in 952e614
polar/examples/snowbox/index.js
Line 173 in 952e614
| const map = useTemplateRef('map') | ||
|
|
||
| createMap( | ||
| await createMap( |
There was a problem hiding this comment.
@warm-coolguy I think your expectation is handled in #356 ; have a look at
polar/examples/snowbox/index.js
Line 63 in 952e614
polar/examples/snowbox/index.js
Line 173 in 952e614
| const map = useTemplateRef('map') | ||
|
|
||
| createMap( | ||
| await createMap( |
| const overlay = useTemplateRef<typeof PolarMapOverlay>('polar-map-overlay') | ||
|
|
||
| let map: Map | null = null | ||
| let map: Map = {} as Map |
| if (coreStore.configuration.checkServiceAvailability) { | ||
| checkServiceAvailability(coreStore.configuration, serviceRegister) | ||
| } |
There was a problem hiding this comment.
@dopenguin Is there a compelling reason to move this here? As I incorporated the changes from this PR into #356, I stumbled on this, as configureApp doesn't know the configuration anymore.
There was a problem hiding this comment.
Moved this here so it is called earlier than before. Nothing really relevant
There was a problem hiding this comment.
🏓 @dopenguin @oeninghe-dataport Since the conceptional stuff seems to be resolved, more is up to you two guys getting this mergable/merged. I approve as far as my concerns go.
|
Relevant changes have been integrated into #356, closing this PR. |
Summary
The map may not have been initialized if the services weren't fully received from a remote source when a plugin has been added.
Instructions for local reproduction and review
mapinmainStoretonull.coreStore.map.getLayers()insetupPluginoffullscreenand log the result