Skip to content

Commit

Permalink
docs: added docs on rx_collection iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Feb 17, 2023
1 parent 60a60f0 commit d297af1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/perseus/src/state/rx_collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,43 @@
//! without this attribute, the `ReactiveState` derive macro will just wrap
//! the whole field in an `RcSignal` and call it a day, rather than using the
//! fine-grained reactivity enabled by these types.
//!
//! **Also note:** when iterating over any of these collections to create
//! `View` fragments, you will need to use `create_ref()` to prevent lifetime
//! errors in some more complex cases, like so:
//!
//! ```no_run
//! # use serde::{Serialize, Deserialize};
//! # use perseus::state::rx_collections::RxVec;
//! # use sycamore::prelude::*;
//! # use perseus::prelude::*;
//! # #[derive(Serialize, Deserialize, Clone, ReactiveState)]
//! # #[rx(alias = "StateRx")]
//! # struct State {
//! # #[rx(nested)]
//! # list: RxVec<String>,
//! # }
//! #
//! # #[auto_scope]
//! # fn view<G: Html>(cx: Scope, state: &StateRx) -> View<G> {
//! // Note the use of `create_ref()` here
//! let list = create_ref(state.list.get());
//! let view = View::new_fragment(
//! list.iter()
//! .map(|elem| {
//! // ...
//! # view! {
//! (elem)
//! }
//! })
//! .collect()
//! );
//!
//! view! { cx,
//! (view)
//! }
//! # }
//! ```

mod rx_hash_map;
mod rx_hash_map_nested;
Expand Down

0 comments on commit d297af1

Please sign in to comment.