From 8813c8324b9aeb4c84f468ac28dae86273651d07 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 23 Oct 2024 18:50:48 +0200 Subject: [PATCH] Add `Layer::process_command` --- crates/fj-core/src/layers/layer.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 10c4cf0c6..4207f087f 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -23,6 +23,24 @@ impl Layer { Self { state } } + /// # Process a command without capturing any events + /// + /// The command is processed synchronously. When this method returns, the + /// state has been updated. + pub fn process_command(&mut self, command: C) -> C::Result + where + C: Command, + { + let mut events = Vec::new(); + let result = command.decide(&self.state, &mut events); + + for event in events { + event.evolve(&mut self.state); + } + + result + } + /// # Process a command and capture the events that produces /// /// The command is processed synchronously. When this method returns, the