From 86ba49ed0304cd7ee4283e81c155122838f78437 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Mar 2024 13:21:11 +0100 Subject: [PATCH 1/4] Add `ValidateObject` --- crates/fj-core/src/layers/objects.rs | 5 ++++- crates/fj-core/src/layers/validation.rs | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index d3830a30f..312b1a32c 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -5,7 +5,7 @@ use crate::{ validation::Validation, }; -use super::{Command, Event, Layer}; +use super::{validation::ValidateObject, Command, Event, Layer}; impl Layer { /// Insert an object into the stores @@ -20,6 +20,9 @@ impl Layer { self.process(InsertObject { object }, &mut events); for event in events { + let event = ValidateObject { + object: event.object.into(), + }; validation.process(event, &mut Vec::new()); } } diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index a3ac931d3..a75b4c90d 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -5,7 +5,7 @@ use crate::{ validation::{Validation, ValidationError, ValidationErrors}, }; -use super::{objects::InsertObject, Command, Event, Layer}; +use super::{Command, Event, Layer}; impl Layer { /// Take all errors stored in the validation layer @@ -14,14 +14,20 @@ impl Layer { } } -impl Command for InsertObject { +/// Validate an object +pub struct ValidateObject { + /// The object to validate + pub object: AnyObject, +} + +impl Command for ValidateObject { type Result = (); type Event = ValidationFailed; fn decide(self, state: &Validation, events: &mut Vec) { let mut errors = Vec::new(); - let object: AnyObject = self.object.into(); + let object: AnyObject = self.object; object.validate(&state.config, &mut errors); for err in errors { From d69a05aafac95789caf6ce772957a35e7868fcd8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Mar 2024 13:21:29 +0100 Subject: [PATCH 2/4] Update doc comment --- crates/fj-core/src/layers/objects.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index 312b1a32c..4aa192b06 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -29,9 +29,6 @@ impl Layer { } /// Insert an object into the stores -/// -/// This struct serves as both event and command for `Layer`, as well -/// as a command for `Layer`. #[derive(Clone, Debug)] pub struct InsertObject { /// The object to insert From fe59e36339eadbdd93c89d8972ff1a2ce9253c0b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Mar 2024 13:21:50 +0100 Subject: [PATCH 3/4] Inline redundant variable --- crates/fj-core/src/layers/validation.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index a75b4c90d..448cecee9 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -27,12 +27,11 @@ impl Command for ValidateObject { fn decide(self, state: &Validation, events: &mut Vec) { let mut errors = Vec::new(); - let object: AnyObject = self.object; - object.validate(&state.config, &mut errors); + self.object.validate(&state.config, &mut errors); for err in errors { events.push(ValidationFailed { - object: object.clone(), + object: self.object.clone(), err, }); } From 62cb2094bc1350df0295586c0925f7787abd6c1a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Mar 2024 13:22:01 +0100 Subject: [PATCH 4/4] Improve formatting --- crates/fj-core/src/layers/validation.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 448cecee9..402be5e47 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -26,7 +26,6 @@ impl Command for ValidateObject { fn decide(self, state: &Validation, events: &mut Vec) { let mut errors = Vec::new(); - self.object.validate(&state.config, &mut errors); for err in errors {