Repository: GraphiteEditor/Graphite
File: core/document/src/document.rs (Rust)

Code before:
				self.work_mounted = false;
				self.work_mount_path = vec![];
				self.work = Layer::new(LayerDataTypes::Folder(Folder::default()), DAffine2::IDENTITY.to_cols_array(), PathStyle::default());
				let mut responses = vec![];
				for operation in ops.into_iter() {
					if let Some(mut op_responses) = self.handle_operation(operation)? {
						responses.append(&mut op_responses);
					}
				}
				responses.extend(vec![DocumentResponse::DocumentChanged, DocumentResponse::FolderChanged { path }]);

				Some(responses)
			}
			Operation::ToggleVisibility { path } => {
				if let Ok(layer) = self.layer_mut(&path) {
					layer.visible = !layer.visible;
					layer.cache_dirty = true;
				}
				let path = path.as_slice()[..path.len() - 1].to_vec();
				Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::FolderChanged { path }])
			}
			Operation::SetLayerBlendMode { path, blend_mode } => {
				if let Ok(layer) = self.layer_mut(&path) {
					layer.blend_mode = *blend_mode;
					let _ = self.mark_as_dirty(path);
				}

				let path = path.as_slice()[..path.len() - 1].to_vec();

				Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::FolderChanged { path: path.clone() }])
			}
			Operation::FillLayer { path, color } => {
				let layer = self.layer_mut(path).unwrap();
				layer.style.set_fill(layers::style::Fill::new(*color));
				self.mark_as_dirty(path)?;
				Some(vec![DocumentResponse::DocumentChanged])
			}
			Operation::ReorderLayers { source_paths, target_path } => {
				self.reorder_layers(source_paths, target_path)?;

				Some(vec![DocumentResponse::DocumentChanged])
			}
		};
		if !matches!(
			operation,
			Operation::CommitTransaction | Operation::MountWorkingFolder { .. } | Operation::DiscardWorkingFolder | Operation::ClearWorkingFolder
		) {
			self.work_operations.push(operation);
		}
		Ok(responses)
	}

Review comment (suggestion):
this can be replaced by:
```rust
self.mark_as_dirty(path)?;
self.layer_mut(&path).unwrap().blend_mode = *blend_mode;
```

Code after:
				self.work_mounted = false;
				self.work_mount_path = vec![];
				self.work = Layer::new(LayerDataTypes::Folder(Folder::default()), DAffine2::IDENTITY.to_cols_array(), PathStyle::default());
				let mut responses = vec![];
				for operation in ops.into_iter() {
					if let Some(mut op_responses) = self.handle_operation(operation)? {
						responses.append(&mut op_responses);
					}
				}
				responses.extend(vec![DocumentResponse::DocumentChanged, DocumentResponse::FolderChanged { path }]);

				Some(responses)
			}
			Operation::ToggleVisibility { path } => {
				if let Ok(layer) = self.layer_mut(&path) {
					layer.visible = !layer.visible;
					layer.cache_dirty = true;
				}
				let path = path.as_slice()[..path.len() - 1].to_vec();
				Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::FolderChanged { path }])
			}
			Operation::SetLayerBlendMode { path, blend_mode } => {
				self.mark_as_dirty(path)?;
				self.layer_mut(&path).unwrap().blend_mode = *blend_mode;

				let path = path.as_slice()[..path.len() - 1].to_vec();

				Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::FolderChanged { path: path.clone() }])
			}
			Operation::FillLayer { path, color } => {
				let layer = self.layer_mut(path).unwrap();
				layer.style.set_fill(layers::style::Fill::new(*color));
				self.mark_as_dirty(path)?;
				Some(vec![DocumentResponse::DocumentChanged])
			}
			Operation::ReorderLayers { source_paths, target_path } => {
				self.reorder_layers(source_paths, target_path)?;

				Some(vec![DocumentResponse::DocumentChanged])
			}
		};
		if !matches!(
			operation,
			Operation::CommitTransaction | Operation::MountWorkingFolder { .. } | Operation::DiscardWorkingFolder | Operation::ClearWorkingFolder
		) {
			self.work_operations.push(operation);
		}
		Ok(responses)
	}
}