Skip to content

Commit

Permalink
examples/todomvc - Rename Todos::new() Todos::default(). (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfrances107 authored Mar 3, 2024
1 parent 9e2fb62 commit 4bb43f6
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions examples/todomvc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ pub struct Todos(pub Vec<Todo>);

const STORAGE_KEY: &str = "todos-leptos";

// Basic operations to manipulate the todo list: nothing really interesting here
impl Todos {
pub fn new() -> Self {
impl Default for Todos {
fn default() -> Self {
let starting_todos =
window()
.local_storage()
Expand All @@ -23,7 +22,10 @@ impl Todos {
.unwrap_or_default();
Self(starting_todos)
}
}

// Basic operations to manipulate the todo list: nothing really interesting here
impl Todos {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
Expand Down Expand Up @@ -86,12 +88,6 @@ impl Todos {
}
}

impl Default for Todos {
fn default() -> Self {
Self::new()
}
}

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct Todo {
pub id: Uuid,
Expand Down Expand Up @@ -136,7 +132,7 @@ const ENTER_KEY: u32 = 13;
#[component]
pub fn TodoMVC() -> impl IntoView {
// The `todos` are a signal, since we need to reactively update the list
let (todos, set_todos) = create_signal(Todos::new());
let (todos, set_todos) = create_signal(Todos::default());

// We provide a context that each <Todo/> component can use to update the list
// Here, I'm just passing the `WriteSignal`; a <Todo/> doesn't need to read the whole list
Expand Down

0 comments on commit 4bb43f6

Please sign in to comment.