Skip to content

Instantly share code, notes, and snippets.

@gannebamm
Created January 22, 2020 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gannebamm/6b067ff067a58d21b7bb17c6211d5390 to your computer and use it in GitHub Desktop.
Save gannebamm/6b067ff067a58d21b7bb17c6211d5390 to your computer and use it in GitHub Desktop.
mutally exclusive layers in group with title 'exclusive'
// LINE 146
case CHANGE_LAYER_PROPERTIES: {
const flatLayers = (state.flat || []);
let isBackground = flatLayers.reduce(
(background, layer) => background || (layer.id === action.layer && layer.group === 'background'),
false);
const newLayers = flatLayers.map((layer) => {
if ( includes(castArray(action.layer), layer.id )) {
return assign(
{},
layer,
action.newProperties,
action.params
? {
params: assign({}, layer.params, action.params)
}
: {});
} else if (layer.group === 'background' && isBackground && action.newProperties && action.newProperties.visibility) {
// TODO remove
return assign({}, layer, {visibility: false});
}
// check if layer shall be exclusive
const groups = (state.groups);
for (let i in groups) {
const group = groups[i];
if (group.id === layer.group) {
// get group of layer
if (group.title === 'exclusive') {
if (action.newProperties && action.newProperties.visibility) {
console.log(layer.title + " should not be visible anymore");
return assign({}, layer, {visibility: false});
}
}
}
}
return assign({}, layer);
});
return assign({}, state, {flat: newLayers});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment