Skip to content

Commit

Permalink
Remove redundant command
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Feb 15, 2024
1 parent 0e5ab8d commit 421bdb9
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions crates/fj-core/src/layers/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,14 @@ impl Layer<Objects> {
validation: &mut Layer<Validation>,
) {
let mut events = Vec::new();
self.process(ObjectsCommand::InsertObject { object }, &mut events);
self.process(InsertObject { object }, &mut events);

for event in events {
validation.process(event, &mut Vec::new());
}
}
}

/// Command for `Layer<Objects>`
#[derive(Debug)]
pub enum ObjectsCommand {
/// Insert an object into the stores
///
/// This is the one primitive operation that all other operations are built
/// upon.
InsertObject {
/// The object to insert
object: AnyObject<AboutToBeStored>,
},
}

impl Command<Objects> for ObjectsCommand {
type Event = InsertObject;

fn decide(self, _: &Objects, events: &mut Vec<Self::Event>) {
let ObjectsCommand::InsertObject { object } = self;
events.push(InsertObject { object });
}
}

/// Insert an object into the stores
///
/// Event produced by `Layer<Objects>`.
Expand All @@ -54,6 +32,14 @@ pub struct InsertObject {
pub object: AnyObject<AboutToBeStored>,
}

impl Command<Objects> for InsertObject {
type Event = InsertObject;

fn decide(self, _: &Objects, events: &mut Vec<Self::Event>) {
events.push(self);
}
}

impl Event<Objects> for InsertObject {
fn evolve(&self, state: &mut Objects) {
self.object.clone().insert(state);
Expand Down

0 comments on commit 421bdb9

Please sign in to comment.