Skip to content

Commit 49ca37d

Browse files
committed
Add model parameter to the Widget::init_view() method
Fix #32
1 parent 8e6105e commit 49ca37d

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ documentation = "https://docs.rs/relm/"
66
license = "MIT"
77
name = "relm"
88
repository = "https://github.com/antoyo/relm"
9-
version = "0.9.4"
9+
version = "0.9.5"
1010

1111
[badges]
1212
travis-ci = { repository = "antoyo/relm" }

examples/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct LabelModel {
4545

4646
#[widget]
4747
impl Widget for Label {
48-
fn init_view(&self) {
48+
fn init_view(&self, _model: &mut LabelModel) {
4949
self.label.set_text("Test");
5050
}
5151

examples/webkit-test/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub enum Msg {
5050

5151
#[widget]
5252
impl Widget for Win {
53-
fn init_view(&self) {
53+
fn init_view(&self, _model: &mut Model) {
5454
self.webview.load_uri("https://crates.io/");
5555
}
5656

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
/*
4444
* TODO: look at how Elm works with the <canvas> element.
45+
* TODO: allow adding arbitrary methods in the impl for the #[widget] to allow updating the models
46+
* in method external to the trait.
4547
* TODO: support msg variant with multiple values?
4648
TODO: after switching to futures-glib, remove the unnecessary Arc, Mutex and Clone.
4749
* FIXME: the widget-list example can trigger (and is broken) the following after removing widgets, adding new
@@ -190,10 +192,11 @@ macro_rules! use_impl_self_type {
190192
}
191193

192194
// TODO: remove this hack.
193-
/// A small type to avoid running the destructor of `T`
195+
#[doc(hidden)]
194196
pub struct ManuallyDrop<T> { inner: Option<T> }
195197

196198
impl<T> ManuallyDrop<T> {
199+
#[doc(hidden)]
197200
pub fn new(t: T) -> ManuallyDrop<T> {
198201
ManuallyDrop { inner: Some(t) }
199202
}
@@ -400,7 +403,10 @@ fn create_widget<WIDGET>(remote: &Remote, model_param: WIDGET::ModelParam) -> Co
400403
};
401404
(view, relm.model)
402405
};
403-
widget.init_view();
406+
{
407+
let mut model_guard = model.lock().unwrap();
408+
widget.init_view(&mut *model_guard);
409+
}
404410

405411
{
406412
let mut widget = widget.clone();

src/widget.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub trait Widget
4141
/// Update the view after it is initially created.
4242
/// This method is only useful when using the `#[widget]` attribute, because when not using it,
4343
/// you can use the [`view()`](trait.Widget.html#tymethod.view) method instead.
44-
fn init_view(&self) {
44+
fn init_view(&self, _model: &mut Self::Model) {
4545
}
4646

4747
/// Create the initial model.

0 commit comments

Comments
 (0)