Permalink
Browse files

Add model parameter to the Widget::init_view() method

Fix #32
  • Loading branch information...
antoyo committed Apr 30, 2017
1 parent 8e6105e commit 49ca37deec56ed5aeb0f818d2dac6799501bd1a8
Showing with 12 additions and 6 deletions.
  1. +1 −1 Cargo.toml
  2. +1 −1 examples/simple.rs
  3. +1 −1 examples/webkit-test/src/main.rs
  4. +8 −2 src/lib.rs
  5. +1 −1 src/widget.rs
View
@@ -6,7 +6,7 @@ documentation = "https://docs.rs/relm/"
license = "MIT"
name = "relm"
repository = "https://github.com/antoyo/relm"
version = "0.9.4"
version = "0.9.5"
[badges]
travis-ci = { repository = "antoyo/relm" }
View
@@ -45,7 +45,7 @@ pub struct LabelModel {
#[widget]
impl Widget for Label {
fn init_view(&self) {
fn init_view(&self, _model: &mut LabelModel) {
self.label.set_text("Test");
}
@@ -50,7 +50,7 @@ pub enum Msg {
#[widget]
impl Widget for Win {
fn init_view(&self) {
fn init_view(&self, _model: &mut Model) {
self.webview.load_uri("https://crates.io/");
}
View
@@ -42,6 +42,8 @@
/*
* TODO: look at how Elm works with the <canvas> element.
* TODO: allow adding arbitrary methods in the impl for the #[widget] to allow updating the models
* in method external to the trait.
* TODO: support msg variant with multiple values?
TODO: after switching to futures-glib, remove the unnecessary Arc, Mutex and Clone.
* 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 {
}
// TODO: remove this hack.
/// A small type to avoid running the destructor of `T`
#[doc(hidden)]
pub struct ManuallyDrop<T> { inner: Option<T> }
impl<T> ManuallyDrop<T> {
#[doc(hidden)]
pub fn new(t: T) -> ManuallyDrop<T> {
ManuallyDrop { inner: Some(t) }
}
@@ -400,7 +403,10 @@ fn create_widget<WIDGET>(remote: &Remote, model_param: WIDGET::ModelParam) -> Co
};
(view, relm.model)
};
widget.init_view();
{
let mut model_guard = model.lock().unwrap();
widget.init_view(&mut *model_guard);
}
{
let mut widget = widget.clone();
View
@@ -41,7 +41,7 @@ pub trait Widget
/// Update the view after it is initially created.
/// This method is only useful when using the `#[widget]` attribute, because when not using it,
/// you can use the [`view()`](trait.Widget.html#tymethod.view) method instead.
fn init_view(&self) {
fn init_view(&self, _model: &mut Self::Model) {
}
/// Create the initial model.

0 comments on commit 49ca37d

Please sign in to comment.