-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
section 3.5 Iterating over More Complex Data - error in Stores example? #174
Comments
The example in the book (with the two struct definitions and the code below) compiles. Based on the error message, I wonder whether one of the Reading through the Claude conversation here, Claude seems to have changed the meaning of the code here in a pretty significant way— and then lied to you with confidence!
Nope! Working example #[derive(Store, Debug, Clone)]
pub struct Data {
#[store(key: String = |row| row.key.clone())]
rows: Vec<DatabaseEntry>,
}
#[derive(Store, Debug, Clone)]
struct DatabaseEntry {
key: String,
value: i32,
}
#[component]
pub fn App() -> impl IntoView {
// instead of a single with the rows, we create a store for Data
let data = Store::new(Data {
rows: vec![
DatabaseEntry {
key: "foo".to_string(),
value: 10,
},
DatabaseEntry {
key: "bar".to_string(),
value: 20,
},
DatabaseEntry {
key: "baz".to_string(),
value: 15,
},
],
});
view! {
// when we click, update each row,
// doubling its value
<button on:click=move |_| {
// allows iterating over the entries in an iterable store field
use reactive_stores::StoreFieldIterator;
// calling rows() gives us access to the rows
for row in data.rows().iter_unkeyed() {
*row.value().write() *= 2;
}
// log the new value of the signal
leptos::logging::log!("{:?}", data.get());
}>
"Update Values"
</button>
// iterate over the rows and display each value
<For
each=move || data.rows()
key=|row| row.read().key.clone()
children=|child| {
let value = child.value();
view! { <p>{move || value.get()}</p> }
}
/>
}
} |
To bad LLMs, still not excelling at coding, are becoming better "Automated Bullshit Generators" ;-) Your hunch "Based on the error message, I wonder whether one of the Store derives was missing in what you tried?" Turned out to be exactly correct! I had #[derive(Debug, Clone)]
struct DatabaseEntry {
key: String,
value: i32,
} That was a tough one for me. The error appeared so far from the real problem and mentioned an actual error outside my code without providing a reference to the actual location... Thank you ever so much for your help, and for Leptos! |
I've assembled the Stores example as provided in section "3.5 Iterating over More Complex Data Option 4: Stores".
I'm getting an error "no method named
value
found for structAtIndex
in the current scope".I get this error at two locations:
Not seeing a solution, and having no understanding of Leptos internals, I submitted the issue to Windsurf/Cascade using Claude 3.5 and received this explanation and solution:
Line 57 click handler
Claude (edited):
Claude proposed fix, change the above to:
Claude explanation (edited):
Line 66 For loop
Claude: (edited)
Claude proposed fix, change the above to:
Claude explanation (edited):
These changes appear to resolve the issues. The code compiles and runs as expected.
Questions:
Thank you for reading this!
The text was updated successfully, but these errors were encountered: