Skip to content

Commit

Permalink
upgrade to Yew 0.15, with keyed attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Korede-TA committed Apr 30, 2020
1 parent 4b50ad2 commit d133e1b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 66 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -5,7 +5,7 @@ authors = ["Korede Aderele <kaderele@gmail.com>"]
edition = "2018"

[dependencies]
yew = { version = "0.12", features = ["toml", "yaml", "msgpack", "cbor"] }
yew = { version = "0.15", package = "yew-stdweb", features = ["toml", "yaml", "msgpack", "cbor"] }
maplit = "1.0.2"
# cargo-web = "0.6.26"
stdweb = "0.4.3"
Expand Down Expand Up @@ -43,4 +43,4 @@ features = [
'HtmlElement',
'Node',
'Window',
]
]
28 changes: 16 additions & 12 deletions src/model.rs
Expand Up @@ -7,9 +7,11 @@ use std::ops::Deref;
use std::option::Option;
use stdweb::traits::IEvent;
use stdweb::unstable::TryInto;
use stdweb::web::event::{
ContextMenuEvent, IKeyboardEvent, KeyDownEvent, KeyPressEvent, KeyUpEvent,
};
use stdweb::web::{document, IElement, INode, IParentNode};
use wasm_bindgen::JsValue;
use yew::events::{KeyDownEvent, KeyPressEvent, KeyUpEvent};
use yew::prelude::*;
use yew::services::reader::{File, FileData, ReaderService, ReaderTask};
use yew::services::ConsoleService;
Expand Down Expand Up @@ -832,8 +834,9 @@ impl Component for Model {

Action::ReadSession(file) => {
let callback = self.link.callback(Action::LoadSession);
let task = self.reader.read_file(file, callback);
self.tasks.push(task);
if let Ok(task) = self.reader.read_file(file, callback) {
self.tasks.push(task);
}
false
}

Expand Down Expand Up @@ -974,16 +977,19 @@ impl Component for Model {
.link
.callback(|file_data| Action::UploadDriverMiscFile(file_data));
for file in misc_files {
let task = self.reader.read_file(file, upload_callback.clone());
self.tasks.push(task);
if let Ok(task) = self.reader.read_file(file, upload_callback.clone()) {
self.tasks.push(task);
}
}

// Load main driver file. After this task has been scheduled and executed, the
// driver is ready for use.
self.tasks.push(
self.reader
.read_file(main_file, self.link.callback(Action::LoadDriverMainFile)),
);
if let Ok(task) = self
.reader
.read_file(main_file, self.link.callback(Action::LoadDriverMainFile))
{
self.tasks.push(task);
}

false
}
Expand All @@ -996,10 +1002,9 @@ impl Component for Model {
// https://www.tutorialspoint.com/electron/electron_inter_process_communication.htm
// And here, for the documentation for the electon_sys Rust bindings for electron.ipcRenderer:
// https://docs.rs/electron-sys/0.4.0/electron_sys/struct.IpcRenderer.html

let args: [JsValue; 2] = [
JsValue::from_str(file_data.name.deref()),
JsValue::from_str(std::str::from_utf8(&file_data.content).unwrap()),
JsValue::from_str(std::str::from_utf8(&file_data.content).unwrap_or("")),
];
ipc_renderer.send_sync("upload-driver-misc-file", Box::new(args));
false
Expand Down Expand Up @@ -1651,7 +1656,6 @@ impl Component for Model {
}

Action::SetCurrentDefinitionName(name) => {
info! {"current defn name: {}", name};
self.default_definition_name = name;
false
}
Expand Down
9 changes: 0 additions & 9 deletions src/util.rs
Expand Up @@ -35,15 +35,6 @@ pub fn move_grammar(m: &mut Model, source: Coordinate, dest: Coordinate) {
m.get_session_mut()
.grammars
.insert(dest.clone(), source_grammar.clone());
// if a grammar is being moved from root to the meta, clear the original value
// this might not be the behaviour moving forward so we can take that out
if coord!("root").is_n_parent(&source.clone()).is_some()
&& coord!("meta").is_n_parent(&dest.clone()).is_some()
{
m.get_session_mut()
.grammars
.insert(source.clone(), Grammar::default());
}
// resizes new grammar
let row_height = m.row_heights.get(&source.full_row()).unwrap_or(&30.0);
let col_width = m.col_widths.get(&source.full_col()).unwrap_or(&90.0);
Expand Down
87 changes: 44 additions & 43 deletions src/view.rs
Expand Up @@ -4,8 +4,11 @@ use std::rc::Rc;
use stdweb::traits::IEvent;
use stdweb::unstable::TryFrom;
use stdweb::unstable::TryInto;
use stdweb::web::event::{
ClickEvent, IKeyboardEvent, IMouseEvent, KeyDownEvent, KeyPressEvent, MouseDownEvent,
MouseOverEvent,
};
use stdweb::web::{html_element::InputElement, HtmlElement, IHtmlElement};
use yew::events::{ClickEvent, IKeyboardEvent, IMouseEvent, KeyPressEvent};
use yew::prelude::*;
use yew::services::reader::File;
use yew::virtual_dom::vlist::VList;
Expand Down Expand Up @@ -203,56 +206,54 @@ pub fn view_menu_bar(m: &Model) -> Html {
// - the last selected cell is the last (bottom-rightmost) child of the parent
// cell, which should be a Kind::Grid grammar
(Some(first), Some(last)) if first.parent() == last.parent() => {
if let Some((Kind::Grid(sub_coords))) =
/* get the coordinate of the parent, lookup the grammar, then get the grammar.kind */
first
if let Some((Kind::Grid(sub_coords))) = /* get the coordinate of the parent, lookup the grammar, then get the grammar.kind */
first
.parent()
.and_then(|c| m.get_session().grammars.get(&c))
.map(|g| (g.kind.clone()))
{
use std::cmp::Ordering;
let mut sc = sub_coords.clone();
sc.sort_by(|(a_row, a_col), (b_row, b_col)| {
if a_row > b_row {
{
use std::cmp::Ordering;
let mut sc = sub_coords.clone();
sc.sort_by(|(a_row, a_col), (b_row, b_col)| {
if a_row > b_row {
Ordering::Greater
} else if a_row < b_row {
Ordering::Less
} else {
if a_col > b_col {
Ordering::Greater
} else if a_row < b_row {
} else if a_col < b_col {
Ordering::Less
} else {
if a_col > b_col {
Ordering::Greater
} else if a_col < b_col {
Ordering::Less
} else {
Ordering::Equal
}
Ordering::Equal
}
});
let first_sc = sc.first().expect(
"add_definition_button: expect selection parent sub_coords.len > 1",
);
let last_sc = sc.last().expect(
"add_definition_button: expect selection parent sub_coords.len > 1",
);
let defn_name = if m.default_definition_name == "" {
first.parent().unwrap().to_string().replace("-", "_")
} else {
m.default_definition_name.clone()
};
(
// can add definition?
*first_sc == first.row_col() &&
*last_sc == last.row_col(),
// definition name
defn_name.clone(),
// callback
m.link.callback(move |_| {
// Action::AddDefinition(first.parent().unwrap(), defn_name.clone(), true)
Action::StageDefinition(first.parent().unwrap(), defn_name.clone())
}),
)
}
});
let first_sc = sc.first().expect(
"add_definition_button: expect selection parent sub_coords.len > 1",
);
let last_sc = sc.last().expect(
"add_definition_button: expect selection parent sub_coords.len > 1",
);
let defn_name = if m.default_definition_name == "" {
first.parent().unwrap().to_string().replace("-", "_")
} else {
(false, "".to_string(), m.link.callback(|_| Action::Noop))
}
m.default_definition_name.clone()
};
(
// can add definition?
*first_sc == first.row_col() && *last_sc == last.row_col(),
// definition name
defn_name.clone(),
// callback
m.link.callback(move |_| {
// Action::AddDefinition(first.parent().unwrap(), defn_name.clone(), true)
Action::StageDefinition(first.parent().unwrap(), defn_name.clone())
}),
)
} else {
(false, "".to_string(), m.link.callback(|_| Action::Noop))
}
}
_ => (false, "".to_string(), m.link.callback(|_| Action::Noop)),
};
Expand Down

0 comments on commit d133e1b

Please sign in to comment.