-
Notifications
You must be signed in to change notification settings - Fork 42
Fix layer property reactivity #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix layer property reactivity #368
Conversation
|
Hi guys, here is where to take a closer look:
Unfortunately I will have to focus on other projects again in the upcoming months, so take your time for review. Cheers Felix |
…rcome problems with layer- properties reactivity.
…roperties of the layer, no more need to register for specific ones.
… Minor adjustments in various components to correctly pass the raw layer into APIs and deal with initial case when layers is undefined.
…tive components and handle raw conversions.
68bc127 to
75a9fc7
Compare
|
Hi everyone, I’ve just updated this PR. With the changes in Vue 3, the reactivity system has improved significantly, particularly with the introduction of proxies. However, the core issue remains: Vue’s reactivity doesn't track changes made to objects unless those changes go through its reactive proxy. In our case, OpenLayers layers are managed internally by the OpenLayers API, which means we can't guarantee that all changes to those layer objects will be made via Vue’s reactive system. To work around this limitation, I’ve introduced proxy objects that wrap the layer instances. This allows us to better integrate with Vue's reactivity while preserving compatibility with OpenLayers. The implementation should be feature complete:
Some of the components still use the raw OL layers, e.g. Geolocator, as they don`t require any reactivity and are not obtaining their layers via Map composable. Do we see any need to change those? For testing: To see an example, where reactivity failed previously: Open the layer list module and switch the language. Cheers Felix |
…layer_property_reactivity
|
Here's another problem to think about: OpenLayers defines a bunch of getter functions to obtain specific properties: Now there are 2 ways to deal with it:
|
|
I decided to go with approach 2 and map all getter functions declared in One last question: Is |
ccaf2f3 to
75f24ef
Compare
…layer_property_reactivity
This is my take on how we could possibly fix the layer-property-reactivity issue mentioned in #365.
To keep changes minimal I decided to wrap up OL layers and OL layer collections by proxy objects. The proxy objects behave mostly transparent and forward invocations to the underlying layer / collection objects, so they can be basically used as a drop-in. Apparently, use them only for Vue components when reactivity is required.
Using LayerProxy around an OL layer:
layerProxy = new LayerProxy(myLayer)layerProxy.destroy()layerProxy.toRaw()Internally, the layer proxy traps the
getProperties()andget()methods to return a self managed object of key value pairs, which is synced via OL observables.Similarly, using LayerProxyCollection around an OL Collection:
collectionProxy = new LayerCollectionProxy(myLayerCollection);collectionProxy.destroy()collectionProxy.toRaw()Internally, the collection proxy traps the
forEach(),item()andgetArray()methods to return LayerProxy objects.Currently the application uses only a single instance of
LayerProxyCollection, which is managed insidecomposables\Map. TheuseMapfunction which formerly returned a list of layers has been altered to return theLayerProxyCollection. As a result instances ofLayerProxyobjects are also shared between components to make this as resource friendly as possible.However constructing additional
LayerProxyCollectionandLayerProxyobjects is feasible if it should be required by some components (although I dont see yet why this should be necessary).