chore: bootstrap nana-story M0
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
use nana_domain::{RuntimeState, StateDelta};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error, PartialEq, Eq)]
|
||||
pub enum ReduceError {
|
||||
#[error("state delta is not implemented yet: {0} operation(s)")]
|
||||
NotImplemented(usize),
|
||||
}
|
||||
|
||||
/// M0 contract seam. M1 replaces this placeholder with the only authoritative
|
||||
/// state mutation path in the application.
|
||||
pub fn apply_delta(state: &RuntimeState, delta: &StateDelta) -> Result<RuntimeState, ReduceError> {
|
||||
if delta.ops.is_empty() {
|
||||
Ok(state.clone())
|
||||
} else {
|
||||
Err(ReduceError::NotImplemented(delta.ops.len()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use nana_domain::{RuntimeState, StateDelta};
|
||||
|
||||
use super::apply_delta;
|
||||
|
||||
#[test]
|
||||
fn empty_delta_is_identity() {
|
||||
let state = RuntimeState {
|
||||
story_id: "story_demo".to_owned(),
|
||||
current_node: "node_001".to_owned(),
|
||||
current_branch: "branch_main".to_owned(),
|
||||
world_flags: BTreeMap::new(),
|
||||
relationships: BTreeMap::new(),
|
||||
relationship_states: Vec::new(),
|
||||
promises: Vec::new(),
|
||||
knowledge: Vec::new(),
|
||||
items: Vec::new(),
|
||||
clocks: Vec::new(),
|
||||
checks: Vec::new(),
|
||||
};
|
||||
assert_eq!(
|
||||
apply_delta(&state, &StateDelta { ops: Vec::new() }),
|
||||
Ok(state)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user