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

Add Each::from_vec for Each #18

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cli/src/ext/exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Command for CommandTailwind {
"tailwindcss"
}
fn default_version(&self) -> &'static str {
"v3.3.3"
"v3.3.5"
}
fn env_var_version_name(&self) -> &'static str {
ENV_VAR_GLORY_TAILWIND_VERSION
Expand Down
22 changes: 20 additions & 2 deletions crates/core/src/widgets/each.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,27 @@ where
TmplFn: Fn(&Value) -> Tmpl + 'static,
Tmpl: Widget + 'static,
{
pub fn new(items: Lotus<ITter>, key_fn: KeyFn, tmpl_fn: TmplFn) -> Self {
pub fn new(items: impl Into<Lotus<ITter>>, key_fn: KeyFn, tmpl_fn: TmplFn) -> Self {
Self {
items,
items: items.into(),
key_fn,
tmpl_fn,
key_view_ids: IndexMap::new(),
_pd: PhantomData,
}
}
}
impl<Value, KeyFn, Key, TmplFn, Tmpl> Each<Value, Vec<Value>, KeyFn, Key, TmplFn, Tmpl>
where
Value: fmt::Debug + 'static,
KeyFn: Fn(&Value) -> Key + 'static,
Key: Eq + Hash + Clone + fmt::Debug + 'static,
TmplFn: Fn(&Value) -> Tmpl + 'static,
Tmpl: Widget + 'static,
{
pub fn from_vec(items: impl Into<Lotus<Vec<Value>>>, key_fn: KeyFn, tmpl_fn: TmplFn) -> Self {
Self {
items: items.into(),
key_fn,
tmpl_fn,
key_view_ids: IndexMap::new(),
Expand Down
3 changes: 1 addition & 2 deletions examples/hackernews-salvo/src/views/story/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ impl Widget for ListStories {
},
|stories, ctx| {
if let Some(stories) = stories {
ul().fill(Each::new(
Lotus::<Vec<Story>>::from(stories.clone()),
ul().fill(Each::from_vec(stories.clone(),
|story: &Story| story.id,
|story| ShowStory::new(story.clone()),
))
Expand Down
6 changes: 2 additions & 4 deletions examples/hackernews-salvo/src/views/story/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ impl Widget for ShowStory {
})
.case(Cage::new(true), || span().html("No comments yet.")),
)
.fill(ul().class("comment-children").fill(Each::new(
Lotus::<Vec<Comment>>::from(story.comments.clone()),
.fill(ul().class("comment-children").fill(Each::from_vec(story.comments.clone(),
|comment| comment.id,
|comment| ShowComment::new(comment.clone()),
))),
Expand Down Expand Up @@ -140,8 +139,7 @@ impl Widget for ShowComment {
.fill(Switch::new().case(opened.clone(), {
let comments = Cage::new(comment.comments.clone());
move || {
ul().class("comment-children").fill(Each::new(
Lotus::<Vec<Comment>>::from(comments.clone()),
ul().class("comment-children").fill(Each::from_vec(comments.clone(),
|comment| comment.id,
|comment| ShowComment::new(comment.clone()),
))
Expand Down