Open aldebaranzbradaradjan opened 4 years ago
Heads up I plan to address this issue over the weekend! Hang tight, sorry!
What is Subscription
? Can you show me the definition for that?
In terms of requestAnimationFrame, I can update the example to show how to do it.
I'd like to rewrite the example using some of the things that I've learned in the last couple of years, so this can be part of that work stream.
Hi, nice to see a response :)
So, Subscription is part of redux_rs crate, i think it works like your store in the example here : https://github.com/chinedufn/percy/blob/master/examples/isomorphic/app/src/store.rs and https://github.com/chinedufn/percy/blob/master/examples/isomorphic/client/src/lib.rs
In your example you do this :
// TODO: Use request animation frame from web_sys
// https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Window.html#method.request_animation_frame
app.store.borrow_mut().subscribe(Box::new(|| {
web_sys::console::log_1(&"Updating state".into());
global_js.update();
}));
The definition of Subscription : https://docs.rs/redux-rs/0.1.0/redux_rs/type.Subscription.html The definition force the use of a function ( fn(_: &State); ) but if i use a closure that catch scope variables it can't be converted as function, it's remain as a closure. So I can maybe call my render update with the subscription of redux_rs if I modify the crate, but I don't know how to do this. This is why I'm interested by your solution with request_animation_frame :)
I will wait for your example rewrite in this case ! Thanks !
I'm playing with Percy, and it's pretty cool, really a good feeling. But i'm not satisfied by the way I update my views. In the isomorphic example you use a call to a function in JS from the rust listener to call a render code in the same crate, and you suggest to replace all of that by the use of request_animation_frame from rust : https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Window.html#method.request_animation_frame .
But i can't figure how to do that, can you help me ? By the way i use the method of global js call, it's working but i'm curious :)
I can't find a way to update my view when my data is modified. Redux provide listeners, so i can do that :
But to upgrade my view I need a ref to the updater in the closure, so, i have add a move before my closure like this this :
After that, subscribers complain that it is not a function but a closure :
I did a research, a closure can be converted to an anonymous function but not if it captures its environment. So when I use move, it's not convertible to function and it doesn't work anymore
Do you know how i can update my view with this callback ? I'm very new to Rust.
I put my code in example of the pb :
It's working but use code from Js to call render in Rust, I would love to do thing like that :