Comments (5)
Something like this in Angular?
I was able to add a focus-selector to the counter example with the addition of the following code:
use wasm_bindgen::JsCast; // Not required once seed::to_html_el is live
// in Msg:
Focus(&'static str),
// (in update):
Msg::Focus(el_id) => {
let document = web_sys::window().unwrap().document().unwrap();
let input = document.get_element_by_id(el_id).unwrap();
let input = input.dyn_into::<web_sys::HtmlElement>().unwrap();
// let input = seed::to_html_el(&input);
input.focus().unwrap();
model
}
/// In bottom of view func:
input![ attrs!{"id" => "A"} ],
input![ attrs!{"id" => "B"} ],
input![ attrs!{"id" => "C"} ],
button![ "Focus A", simple_ev("click", Msg::Focus("A")) ],
button![ "Focus B", simple_ev("click", Msg::Focus("B")) ],
button![ "Focus C", simple_ev("click", Msg::Focus("C")) ],
Thoughts: This approach is probably prone to bugs in more complicated cases, eg if the input els are destroyed/recreated. Could add a more convenient way to access the window document, since what I posted is verbose. Added seed::to_html_el, to avoid having the user import JsCast, and to simplify syntax. (eg commented code above) web_sys::Element doesn't have focus(); only web_sys::HtmlElement.
More importantly, while this seems to work for your specific example, something more flexible that can be triggered by diff events (destroy, create etc) is needed.
from seed.
thanks for your thoughts and the code example which illustrates how to interact with the underlying domNode.
About the life cycle hooks, I was thinking of react componentDidMount
, componentWillUnmount
, (there are more). I guess most virtual dom based frameworks have something like that. One common use case: integrating third party JS widgets.
from seed.
Adding this to the to-do list. Top priority is the Fetch (Get/Post data from server) API; will probably prioritize this over routing.
from seed.
@rsaccon Implemented. Check out the docs, and examples/counter with version 0.1.11. I'm ill-acquainted with the concept, so let me know if this is correct. If so, I'll close this issue.
from seed.
This looks great! According to my understanding, this is correct. Perfectly documented and I look forward to build a more complex example, eventually I would like to do animations (but I don't know yet how exactly ...)
from seed.
Related Issues (20)
- 1. Create a new issue in the Seed repo with the name and copy-paste this checklist into it (also add blockers and additional tasks, if exist).
- Maintenance & Future of Seed HOT 8
- v0.9.1: browser::json::Error is inaccessible
- Deserializing large numbers fail HOT 11
- Websocket example does not work HOT 2
- how to integrate with another wasm ?
- Websocket API changed from 0.8 to 0.9 HOT 5
- DOM node is not attached to ElRef under some conditions HOT 6
- Does not build with wasm-bindgen 0.2.81 HOT 3
- Closures need types HOT 3
- Release v0.9.2 HOT 3
- Seed 0.8 accepting the newest wasm-bindgen HOT 3
- [0.8.x] WebSocket and too early dropped closure HOT 1
- support `beforeinput` events HOT 1
- Seed doesn't compile with `default-features = false` HOT 2
- checkbox not working HOT 2
- Release v0.10.0 HOT 3
- Cannot use subs (subs::UrlChanged) HOT 2
- Error: unresolved import in wasm_bindgen_initialize HOT 1
- Website defaced by indonesian (?) script-kiddie HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seed.