Skip to content

Commit 894140c

Browse files
committed
switch a deque for easy pushing to front
1 parent 3d56e24 commit 894140c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/wasm/main.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![cfg(feature = "wasm")]
2+
use std::collections::VecDeque;
3+
24
use yew::prelude::*;
35
use yew::virtual_dom::VNode;
46

@@ -10,7 +12,7 @@ pub enum Msg {
1012
}
1113

1214
pub struct App {
13-
images: Vec<VNode>,
15+
images: VecDeque<VNode>,
1416
}
1517

1618
impl Component for App {
@@ -19,26 +21,28 @@ impl Component for App {
1921

2022
fn create(_ctx: &Context<Self>) -> Self {
2123
Self {
22-
images: Vec::default(),
24+
images: VecDeque::default(),
2325
}
2426
}
2527

2628
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
2729
match msg {
2830
Msg::Loaded(file) => {
29-
self.images.push(html! { <ImageComponent file={file} /> });
31+
self.images
32+
.push_front(html! { <ImageComponent file={file} /> });
3033
}
3134
}
3235
true
3336
}
3437

3538
fn view(&self, ctx: &Context<Self>) -> Html {
39+
let images: Vec<VNode> = self.images.clone().into();
3640
html! {
3741
<div id="wrapper">
3842
<h1>{ "Process your CGA/EGAs" }</h1>
3943
<FileInput accept="image/*,.bin,.cga,.ega" onload={ctx.link().callback( Msg::Loaded )} children={None}/>
4044
<div id="preview-area">
41-
{{ self.images.clone() }}
45+
{{ images }}
4246
</div>
4347
</div>
4448
}

0 commit comments

Comments
 (0)