use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompiledArtifact {
pub root_id: u64,
pub view: SerializedView,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SerializedView {
pub view_type: String,
pub props: serde_json::Value,
pub children: Vec<SerializedView>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RuntimePatch {
ReplaceView {
node_id: u64,
new_view: SerializedView,
},
UpdateState {
node_id: u64,
field: String,
value: serde_json::Value,
},
Batch(Vec<RuntimePatch>),
}
pub struct PatchEngine;
impl PatchEngine {
pub fn new() -> Self {
Self
}
pub fn generate_patch(&self, artifact: CompiledArtifact) -> RuntimePatch {
RuntimePatch::Batch(vec![
RuntimePatch::ReplaceView {
node_id: artifact.root_id,
new_view: artifact.view,
}
])
}
}