feat(sync): add typed flat patch boundary

req: sync/002

req: sync/003
This commit is contained in:
slhx agent
2026-07-13 21:02:43 +02:00
parent 25fcdae9b9
commit 34728b9a35
12 changed files with 625 additions and 11 deletions
+1
View File
@@ -29,6 +29,7 @@ axum = { version = "0.8", optional = true }
futures-util = { version = "0.3", optional = true }
hemx = { path = "../../hemx" }
hemx-axum = { path = "../../hemx-axum", optional = true }
hemx-sync = { path = "../../hemx-sync" }
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "time"], optional = true }
+34 -2
View File
@@ -78,14 +78,46 @@ pub fn reorder_card(
let projected =
BoardProjection::restore(state).apply(ReorderCommand::from_client(event).decide());
let card = projected.card.0;
let patch = hemx_sync::FlatPatch::for_interaction(
"cardColumn",
hemx_sync::PatchValue::String("done".to_owned()),
)
.expect("generated Kanban patch is valid");
let move_effect = match projected.before {
Some(before) => ui::client_board::client_cards.move_before(card.clone(), before.0),
None => ui::client_board::client_cards.move_to_end(card.clone()),
};
vec![
(
move_effect,
ui::client_board::client_notice.text(format!("Moved {card} with {}", projected.input_kind)),
]
hemx_sync::SyncEffect::send_patch(patch),
)
}
#[cfg(all(test, feature = "client"))]
mod client_tests {
use super::*;
use hemx::IntoEffect;
#[test]
fn client_reorder_carries_flat_patch_in_ordinary_effect_batch() {
let batch = reorder_card(
hemx::wasm::ClientEvent {
kind: "drop".to_owned(),
value: None,
checked: None,
key: None,
},
hemx::wasm::ClientState {
encoded: "1|2".to_owned(),
},
)
.into_batch(ui::BUILD_FINGERPRINT);
assert_eq!(batch.ops.len(), 3);
assert!(
matches!(&batch.ops[2], hemx::advanced::Effect::Emit { name, payload } if name == hemx_sync::PATCH_EVENT && payload.contains("$hemx-interaction"))
);
}
}
#[cfg(all(feature = "fixture", not(target_arch = "wasm32")))]
+1 -1
View File
@@ -1,4 +1,4 @@
<section data-hemx-root="kanban_client" data-hemx-st="1|2" data-hemx-client-state-version="1" data-hemx-client-module="/kanban_client.js">
<section data-hemx-root="kanban_client" data-hemx-st="1|2" data-hemx-client-state-version="1" data-sync-endpoint="/sync/patches" data-hemx-client-module="/kanban_client.js">
<p id="kanban-status" data-hemx-slot="client_notice" role="status" aria-live="polite">Ready</p>
<ul data-hemx-slot="client_cards">
<template h-for="card in &self.cards" h-key="card.id">