Skip to content
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

feat: basic TODO app; no bells, no whistles #1167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jdevries3133
Copy link
Contributor

I was wishing this was present when trying to learn from the examples in the repo – just a basic client-side TODO app without any server-side code or isomorphism.

I feel like this specific implementation probably stinks – I'm totally new to both Leptos and Rust, so happy to take any feedback & no hard feelings if there isn't interest in pulling an example like this into the repo. I fully appreciate my naive perspective here :)

@jdevries3133 jdevries3133 force-pushed the basic_todo_app branch 2 times, most recently from 276552e to c8373e1 Compare June 10, 2023 02:02
@phillipbaird
Copy link

Would Vec.retain() be a simpler way to implement delete_todo?

@jdevries3133
Copy link
Contributor Author

Would Vec.retain() be a simpler way to implement delete_todo?

Yeah, that's a definite improvement, thank you!

@gbj
Copy link
Collaborator

gbj commented Jun 14, 2023

Thanks for suggesting this! When compared to the todomvc (which is a standard cross-framework example, and is also just client-side-only with no server-side code), is the idea here just that this is even simpler? I think otherwise the basics of a simple component, then iteration are pretty well demonstrated by counter and counters.

@jdevries3133
Copy link
Contributor Author

Maybe this could be called todo_component? I think that not everyone is familiar with the MVC pattern, and this is line-for-line akin to a todo list app that you might see taught to React developers. Nonetheless, my feelings won't be hurt if you think this doesn't fit! I think you are right that the same ideas are represented already in other examples.

}

#[derive(Copy, Clone)]
struct TodoGenerator {
Copy link
Contributor

@flosse flosse Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd split the ID, the Todo and the latest ID state.

e.g.:

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TodoId(u64);

impl TodoId {
    const fn next(self) -> Self {
        Self(self.0 + 1)
    }
}

impl TodoItem {
    const fn new(id: TodoId, name: String) -> Self {
        Self { id, name }
    }
}

fn main(){
    let mut current_id = TodoId::default();
    // ...
    let create_new_item = |title| {
        let next_id = current_id.next();
        current_id = next_id;       
        let todo = TodoItem::new(next_id, title);
    };
}

@gbj
Copy link
Collaborator

gbj commented Apr 17, 2024

@jdevries Sorry for my slow response here. Thanks for your contribution. We have created a new projects directory to house a wider variety of projects without the same maintenance burden as examples — Would you be interested in updating your PR and adding it to projects instead? I totally understand if not, it's been a while :-)

1 similar comment
@gbj
Copy link
Collaborator

gbj commented Apr 17, 2024

@jdevries Sorry for my slow response here. Thanks for your contribution. We have created a new projects directory to house a wider variety of projects without the same maintenance burden as examples — Would you be interested in updating your PR and adding it to projects instead? I totally understand if not, it's been a while :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants