Compare commits

..

4 Commits

Author SHA1 Message Date
Greg Johnston
f7b08cf9cc Merge branch 'main' into server-fn-test-fix 2023-06-13 16:23:46 -04:00
Greg Johnston
7e16d115e3 docs: fix failing doctests for server fns 2023-06-13 16:22:39 -04:00
Greg Johnston
b043f829a6 docs: clarify available server fn encodings (#1178) 2023-06-13 16:01:45 -04:00
jquesada2016
f415f7b146 fix: removes in new <For/> causing panics in some circumstances (#1173) 2023-06-13 15:43:02 -04:00
3 changed files with 29 additions and 5 deletions

View File

@@ -828,7 +828,7 @@ fn apply_diff<T, EF, V>(
}
for DiffOpRemove { at } in &diff.removed {
let item_to_remove = std::mem::take(&mut children[*at]).unwrap();
let item_to_remove = children[*at].take().unwrap();
item_to_remove.prepare_for_move();
}
@@ -910,21 +910,34 @@ fn apply_diff<T, EF, V>(
/// Unpacks adds and moves into a sequence of interleaved
/// add and move commands. Move commands will always return
/// with a `len == 1` and `is_dense = true`.
/// with a `len == 1`.
#[cfg(all(target_arch = "wasm32", feature = "web"))]
fn unpack_moves(diff: &Diff) -> (Vec<DiffOpMove>, Vec<DiffOpAdd>) {
let mut moves = Vec::with_capacity(diff.items_to_move);
let mut adds = Vec::with_capacity(diff.added.len());
let mut removes_iter = diff.removed.iter();
let mut adds_iter = diff.added.iter();
let mut moves_iter = diff.moved.iter();
let mut removes_next = removes_iter.next();
let mut adds_next = adds_iter.next();
let mut moves_next = moves_iter.next().copied();
for i in 0..diff.items_to_move + diff.added.len() {
let mut from_offset: usize = 0;
for i in 0..diff.items_to_move + diff.added.len() + diff.removed.len() {
match (adds_next, &mut moves_next) {
(Some(add), Some(move_)) => {
if let Some(DiffOpRemove { at }) = removes_next {
if *at == i {
from_offset += 1;
removes_next = removes_iter.next();
continue;
}
}
if add.at == i {
adds.push(*add);
@@ -932,6 +945,7 @@ fn unpack_moves(diff: &Diff) -> (Vec<DiffOpMove>, Vec<DiffOpAdd>) {
} else {
let mut single_move = *move_;
single_move.len = 1;
single_move.from -= from_offset;
moves.push(single_move);
@@ -950,8 +964,18 @@ fn unpack_moves(diff: &Diff) -> (Vec<DiffOpMove>, Vec<DiffOpAdd>) {
adds_next = adds_iter.next();
}
(None, Some(move_)) => {
if let Some(DiffOpRemove { at }) = removes_next {
if *at == i {
from_offset += 1;
removes_next = removes_iter.next();
continue;
}
}
let mut single_move = *move_;
single_move.len = 1;
single_move.from -= from_offset;
moves.push(single_move);

View File

@@ -847,7 +847,7 @@ pub fn slot(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
/// of the request. But there are a few other methods supported. Optionally, we can provide another argument to the `#[server]`
/// macro to specify an alternate encoding:
///
/// ```rust
/// ```rust,ignore
/// #[server(AddTodo, "/api", "Url")]
/// #[server(AddTodo, "/api", "GetJson")]
/// #[server(AddTodo, "/api", "Cbor")]

View File

@@ -77,7 +77,7 @@
//! of the request. But there are a few other methods supported. Optionally, we can provide another argument to the `#[server]`
//! macro to specify an alternate encoding:
//!
//! ```rust
//! ```rust,ignore
//! #[server(AddTodo, "/api", "Url")]
//! #[server(AddTodo, "/api", "GetJson")]
//! #[server(AddTodo, "/api", "Cbor")]