Seed: gloo timer

Created on 29 Aug 2019  路  10Comments  路  Source: seed-rs/seed

Hello

When I try to run this example :
https://github.com/David-OConnor/seed/blob/master/examples/orders/src/lib.rs

I get the error :

wasm-bindgen: imported JS function that was not marked as catch threw an error: Illegal invocation

For gloo_timers::sys::clear_timeout

Thanks for your help

All 10 comments

Hi, thanks for report!
Some questions:

  • What's your OS?
  • Wasm-pack's version? (wasm-pack -V)
  • Seed's version? (or you use master branch?)
  • Rust version (rustc -V)
  • Do you see that error even after you delete folder target in Seed's root and pkg in example's folder?
  • Do you use cargo make start orders from Seed's root to start that example?
  • OS : I tried both Windows and Linux
  • wasm-pack 0.8.1
  • seed = "0.4.0"
  • wasm-bindgen = "0.2.47"
  • rustc 1.35.0 (3c235d560 2019-05-20)

Do you see that error even after you delete folder target in Seed's root and pkg in example's folder?

Yes

Do you use cargo make start orders ?

No because cargo make dosen't want to install on my computer

I downgraded to your versions (on Windows) and I'm still not able to reproduce your problems.

cargo make dosen't want to install on my computer

I suggest to focus on cargo make error, because it's maybe somehow related to your issues, your development will be more comfortable and maybe you use different commands (than we use in cargo make start *) which cause problems.

So I downloaded the repo seed
And I did this in :

rustup update
rustup target add wasm32-unknown-unknown
cargo-make: cargo install --force cargo-make
cargo make start orders

And it works

I need to re-test in my project

Hello ,
I just saw that gloo 0.1.0 was realased 4 days ago :
https://crates.io/crates/gloo
馃帀馃帀馃帀

use gloo::{events::EventListener, timers::callback::Timeout};
Timeout::new(1_000, move || {
           log!("test");
         }).forget();

I will try to use I with my project to update model (with a future may-be)

Sweet. We've updated the code to use the crate, but haven't released the new version.

I was able to do this :

use gloo::{timers::callback::Timeout};

Timeout::new(1_000, move || {
                let html_el = seed::document().get_element_by_id("toast").unwrap();
                log!(html_el.class_name());
            }).forget();

But if I try this :

Timeout::new(1_000, move || {
                log!(model.msg);
            }).forget();

I have this error :

explicit lifetime required in the type of model
lifetime 'static required

any idea ?

@TuntematonSotilas: I think that 'static is required in your example because of https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/closure/struct.Closure.html (see description at the top).
So you have to make sure your model is 'static or close only msg (which has to be also 'static, of course).

Example:

let msg = model.msg.clone();
Timeout::new(1_000, move || {
    log!(msg);
}).forget();

Or you can probably use macro enc! or enclose! - https://docs.rs/enclose/1.1.8/enclose/ for more readable code (you can search Seed's code for examples).

@TuntematonSotilas But on the second look - you probably want to know value of property msg from the _current_ model, after the given delay.
So try to get App instance from orders and send it into the closure. App is behind the Rc so it should be 'static and you should be able to get model from it or at least call update function, where you can use current model.
Example here: https://github.com/David-OConnor/seed/blob/master/examples/animation_frame/src/lib.rs#L72

Thanks it works perfectly with :

let (app, msg_mapper) = (orders.clone_app(), orders.msg_mapper());
Timeout::new(5_000, move || {
    app.update(msg_mapper(Msg::Hide));
 }).forget();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

FliegendeWurst picture FliegendeWurst  路  3Comments

songmaotian picture songmaotian  路  4Comments

bgourlie picture bgourlie  路  4Comments

MartinKavik picture MartinKavik  路  3Comments

L0g4n picture L0g4n  路  4Comments