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

Code before:
				responses.push_back(FolderChanged(vec![]).into());
			}
			FolderChanged(path) => {
				let _ = self.graphene_document.render_root(self.view_mode);
				responses.extend([LayerChanged(path).into(), DocumentStructureChanged.into()]);
			}
			DocumentStructureChanged => {
				let data_buffer: RawBuffer = self.serialize_root().into();
				responses.push_back(FrontendMessage::DisplayFolderTreeStructure { data_buffer }.into())
			}
			LayerChanged(path) => {
				if let Ok(layer_entry) = self.layer_panel_entry(path) {
					responses.push_back(FrontendMessage::UpdateLayer { data: layer_entry }.into());
				}
			}
			DispatchOperation(op) => match self.graphene_document.handle_operation(&op) {
				Ok(Some(document_responses)) => {
					for response in document_responses {
						match &response {
							DocumentResponse::FolderChanged { path } => responses.push_back(FolderChanged(path.clone()).into()),
							DocumentResponse::DeletedLayer { path } => {
								self.layer_metadata.remove(path);
							}
							DocumentResponse::LayerChanged { path } => responses.push_back(LayerChanged(path.clone()).into()),
							DocumentResponse::CreatedLayer { path } => {
								if !self.layer_metadata.contains_key(path) {
									self.layer_metadata.insert(path.clone(), LayerMetadata::new(false));
								}
								responses.push_back(LayerChanged(path.clone()).into());
								self.layer_range_selection_reference = path.clone();
								responses.push_back(AddSelectedLayers(vec![path.clone()]).into());
							}
							DocumentResponse::DocumentChanged => responses.push_back(RenderDocument.into()),
						};
						responses.push_back(ToolMessage::DocumentIsDirty.into());
					}
				}
				Err(e) => log::error!("DocumentError: {:?}", e),
				Ok(_) => (),
			},
			RenderDocument => {
				responses.push_back(
					FrontendMessage::UpdateArtwork {
						svg: self.graphene_document.render_root(self.view_mode),
					}
					.into(),
				);
				responses.push_back(ArtboardMessage::RenderArtboards.into());

				let document_transform_scale = self.movement_handler.snapped_scale();
				let scale = 0.5 + ASYMPTOTIC_EFFECT + document_transform_scale * SCALE_EFFECT;

Review comment (suggestion):
I think this should be an error right?
could we maybe add a log::warn! in the else case? I don't think this should ever not be true

Code after:
				responses.push_back(FolderChanged(vec![]).into());
			}
			FolderChanged(path) => {
				let _ = self.graphene_document.render_root(self.view_mode);
				responses.extend([LayerChanged(path).into(), DocumentStructureChanged.into()]);
			}
			DocumentStructureChanged => {
				let data_buffer: RawBuffer = self.serialize_root().into();
				responses.push_back(FrontendMessage::DisplayFolderTreeStructure { data_buffer }.into())
			}
			LayerChanged(path) => {
				if let Ok(layer_entry) = self.layer_panel_entry(path) {
					responses.push_back(FrontendMessage::UpdateLayer { data: layer_entry }.into());
				}
			}
			DispatchOperation(op) => match self.graphene_document.handle_operation(&op) {
				Ok(Some(document_responses)) => {
					for response in document_responses {
						match &response {
							DocumentResponse::FolderChanged { path } => responses.push_back(FolderChanged(path.clone()).into()),
							DocumentResponse::DeletedLayer { path } => {
								self.layer_metadata.remove(path);
							}
							DocumentResponse::LayerChanged { path } => responses.push_back(LayerChanged(path.clone()).into()),
							DocumentResponse::CreatedLayer { path } => {
								if self.layer_metadata.contains_key(path) {
									log::warn!("CreatedLayer overrides existing layer metadata.");
								}
								self.layer_metadata.insert(path.clone(), LayerMetadata::new(false));

								responses.push_back(LayerChanged(path.clone()).into());
								self.layer_range_selection_reference = path.clone();
								responses.push_back(AddSelectedLayers(vec![path.clone()]).into());
							}
							DocumentResponse::DocumentChanged => responses.push_back(RenderDocument.into()),
						};
						responses.push_back(ToolMessage::DocumentIsDirty.into());
					}
				}
				Err(e) => log::error!("DocumentError: {:?}", e),
				Ok(_) => (),
			},
			RenderDocument => {
				responses.push_back(
					FrontendMessage::UpdateArtwork {
						svg: self.graphene_document.render_root(self.view_mode),
					}
					.into(),
				);
				responses.push_back(ArtboardMessage::RenderArtboards.into());