Description
Consider this case:
const layer1 = new RasterLayer(paras);
const layer2 = { ... layer1 }; // This is a common mistake. What user should have done here is `new RasterLayer(layer1);`
layersService.add(layer1);
layersService.add(layer2); // no error here
layer2.visible = !layer2.visible;
layersService.updateLayer(layer2); // error here
This causes an error:
layer with id: <....> you want to update not in storeItems!
This error is thrown because updateLayer calls isInLayergroups which checks if the passed layer is an instance of Layer
if (layergroup instanceof Layer || layergroup instanceof LayerGroup)
Since layer2 was created using object-spread, it does not pass this test.
- What is missing?
- Check that all data that is passed to
addLayer is actually an instance of Layer
- What is it useful for?
- Copying objects using object-spread is very common, especially in state-management-solutions like ngrx. Throwing an error early, that is, at
addLayer and not just at updateLayer, delivers more immediate feedback to the user that the passed data does not contain all the information that Ukis requires.
- Does this change impact existing behaviors? If so how?
- This should not impact functioning code, but might throw errors where others have made that same mistake.
Relevant Package
This feature request is for @dlr-eoc/services-layers
Describe alternatives you've considered
- One could quietly transform non-
Layerobjects into actual instances of Layer in the background. But that would make Ukis harder to understand and encourage passing badly formatted data.
- Alternatively one could not check with
instanceof but rather ducktyping by only checking if the immediately required attributes are present. But that would either lead to yet more checks or to more runtime-errors.
Description
Consider this case:
This causes an error:
This error is thrown because
updateLayercallsisInLayergroupswhich checks if the passed layer is an instance of LayerSince
layer2was created using object-spread, it does not pass this test.addLayeris actually an instance ofLayeraddLayerand not just atupdateLayer, delivers more immediate feedback to the user that the passed data does not contain all the information that Ukis requires.Relevant Package
This feature request is for @dlr-eoc/services-layers
Describe alternatives you've considered
Layerobjects into actual instances ofLayerin the background. But that would make Ukis harder to understand and encourage passing badly formatted data.instanceofbut rather ducktyping by only checking if the immediately required attributes are present. But that would either lead to yet more checks or to more runtime-errors.