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

Upgrade yew to 0.20 #29

Merged
merged 2 commits into from
Dec 3, 2022
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ yew-components = ["api", "yew"]
js-sys = "0.3"
paste = "1.0"
wasm-bindgen = "0.2"
yew = { version = "0.19", optional = true }
yew = { version = "0.20", features = ["csr"], optional = true }

[dependencies.web-sys]
version = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2018"
[dependencies]
monaco = { path = "../..", features = ["yew-components"] }
wasm-bindgen = "0.2"
yew = "0.19"
yew = { version = "0.20", features = ["csr"] }
8 changes: 7 additions & 1 deletion examples/yew/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
import init from "./yew.js";
init();
</script>

<style>
.full-height {
height: 100%;
}
</style>
</head>

<body style="height: 100vh; margin: 0; overflow: hidden;"></body>

</html>
</html>
7 changes: 4 additions & 3 deletions examples/yew/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn get_options() -> CodeEditorOptions {
.with_language("rust".to_owned())
.with_value(CONTENT.to_owned())
.with_builtin_theme(BuiltinTheme::VsDark)
.with_automatic_layout(true)
}

struct App {
Expand All @@ -24,17 +25,17 @@ impl Component for App {
}
}

fn changed(&mut self, _context: &Context<Self>) -> bool {
fn changed(&mut self, _context: &Context<Self>, _old_props: &Self::Properties) -> bool {
false
}

fn view(&self, _context: &Context<Self>) -> Html {
html! {
<CodeEditor options={ self.options.to_sys_options() } />
<CodeEditor classes={"full-height"} options={ self.options.to_sys_options() } />
}
}
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
7 changes: 2 additions & 5 deletions src/yew/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
api::{CodeEditor as CodeEditorModel, TextModel},
sys::editor::IStandaloneEditorConstructionOptions,
};
use std::{cell::RefCell, mem, rc::Rc};
use std::{cell::RefCell, rc::Rc};
use web_sys::HtmlElement;
use yew::{html, html::Scope, Callback, Classes, Component, Context, Html, NodeRef, Properties};

Expand All @@ -31,7 +31,6 @@ pub struct CodeEditorProps<OPT: std::cmp::PartialEq + Clone + Into<IStandaloneEd
/// access the [`CodeEditor`](CodeEditorModel).
#[derive(Debug)]
pub struct CodeEditor {
props: CodeEditorProps,
node_ref: NodeRef,
editor: Option<CodeEditorModel>,
}
Expand Down Expand Up @@ -60,14 +59,12 @@ impl Component for CodeEditor {
}

Self {
props: ctx.props().clone(),
node_ref: NodeRef::default(),
editor: None,
}
}

fn changed(&mut self, ctx: &Context<Self>) -> bool {
let old_props = mem::replace(&mut self.props, ctx.props().clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

yew 0.20 provide access to old_props as a argument to fn changed - I presume this works the same, but please correct me if I'm wrong!

fn changed(&mut self, ctx: &Context<Self>, old_props: &Self::Properties) -> bool {
// these are the new values
let CodeEditorProps {
link,
Expand Down