-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Port Render* split and immutability from native #4875
Comments
I've been thinking a bit about how we should express immutability semantics for this work. gl-native uses a set of generic classes
So far, it looks to me like we can probably only get two out of three of these with JS/Flow (specifically, I don't see a way to get 3 without compromising 2). I'm leaning towards an approach where we:
interface StyleLayer {
/* getters, but no setters */
getMutable(): MutableStyleLayer;
}
interface MutableStyleLayer extends StyleLayer {
/* setters */
}
class StyleLayerImpl implements MutableStyleLayer {
/* getters and setters */
getMutable(): MutableStyleLayer { this.shallowClone(); }
}
Updating state would then look like: setPaintProperty(layerId, name, value) {
// this.layers[layerId].setPaintProperty() would fails, because this.layers[layerId] is typed as StyleLayer, which has no setters
const layer = this.layers[layerId].getMutable();
layer.setPaintProperty(name, value);
const layers = asMutable(this.layers);
layers[name] = layers;
this.layers = layers;
} Slightly more detailed example based on our |
One gotcha we'll have to watch out for is that if a type |
@anandthakker What kind of safety would an Immutable wrapper provide in GL JS? In JS the rendering thread and main thread is the same. The default web worker semantics of web workers are copy. Is the goal to make all data structures accessed by rendering loop wrapped by Immutable to prevent them being accidentally changed by DDS api (Again this should not happen if the main thread and rendering thread is the same). |
@mb12 sure. It's true that thread safety isn't relevant to GL JS. While that was the original motivation for the equivalent gl-native changes, there are other significant benefits to this architecture. @jfirebaugh alludes to some of them above:
Immutability in particular supports (a) simpler and more efficient style diffing, and (b) solving problems involving style state synchronization / consistency (#4012 #6367 #6255) very cleanly--namely, by ensuring that any reference to a style or layer is a reliable snapshot. |
We should replace the current smart
setStyle
implementation in gl-js with one more similar to native, based on a split between:Render*
objects that handle rendering-specific concerns and can update themselves by diffing prior and new immutable objectsThis approach eliminates the complex state tracking needed to track "pending" changes (
Style#_updatedLayers
,_updatedSymbolOrder
,_updatedSources
, etc.).The text was updated successfully, but these errors were encountered: