-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add components #1
Comments
@deniskolodin would this be a 0.2.0 feature too? I'd love to help with this one as it's the one abstraction I think would be nicest. 😄 |
I've been playing around with this implementation. I don't think I should be the implementer, based on the amount of trouble I've been having even coming up with an API, but I have some thoughts. I think each component should have its own lifecycle almost identical to a full yew program. That is to say, each component should have a view, an update, and a model with an internal message type. Each component should also have a public I ran into issues when trying to create a I implemented a potential example in this commit, so this was the example I was trying to get to compile and run. Would love to hear thoughts on this. I think we should really consider what the "modularity", "reusability", and "scaling" stories are for yew before coming up with the exact API for components. That said, I've been very happy with how React handles components, and I think a similar story might work very well for yew if we can work it in with Rust's type system. Callbacks and closures might also not work quite as well as they do in JS for passing up data to parent components, so we might want to have some sort of hook to pass a message up to the parent or global message handler. This is really where I started running into design issues. I also read up on Elm's scaling story and was unimpressed due to the fact that (I believe) it relies on one global message type and model. I think we need a more rigid, opinionated component structure. |
@rivertam @deniskolodin I guess it's a matter of what feels best and where we're taking influence from? I agree that components should have their own lifecycles but I was thinking something more alike to React. I'm also not the strongest in Rust though. Maybe if we could enumerate the things we would want abstracted away we could figure out what that looks like in Rust. |
The good thing about modeling after React is that it encourages "strict" typing very strongly with |
@rivertam Agreed. It doesn't need to look too much like React. I was most interested in taking the ideas around its state management. The abstraction around |
I disagree about state management for two reasons.
Another approach I've been thinking of is more Redux/Elm-like, which would be that we'd have "reducers" (update), "models", and "actions" (messages) which would be specified in the same file as the view and would only affect a certain part of the global model and only receive those messages. I have no idea how we'd implement it, but I feel this might be another reasonable approach. |
Basically copying the API in reason-react should work well. There each component has a message type and reducer to update the state: https://reasonml.github.io/reason-react/docs/en/state-actions-reducer.html ReasonML is in many ways more similar to rust than Elm or JS anyway :) |
Components was implemented with #91 🎉 |
* Early msgs queue for Public worker * Early msgs queue for Public worker * update (#1) * Fix typo * Require fmt in travis script * Apply cargo format to all modules * ?? * Merge (#2) * Fix typo * Require fmt in travis script * Apply cargo format to all modules * avoid allocating in diff_classes * avoid allocating for diff_kind * avoid allocating for diff_value * simplify diff_attributes and avoid allocations * return iterator for diff_classes and diff_attributes * rustfmt on vtags * clean apply_diff * more cleaning * apply suggestions * Update proc-macro2, syn and quote to 1.0 CLOSES #590 * Fixed typo * Add support for optional callbacks to component properties * Add tests for a component with optional callback * Fix typo * Add `Classes` to prelude * binary ser/de issue fix * merge (#3) * Fix typo * Require fmt in travis script * Apply cargo format to all modules * avoid allocating in diff_classes * avoid allocating for diff_kind * avoid allocating for diff_value * simplify diff_attributes and avoid allocations * return iterator for diff_classes and diff_attributes * rustfmt on vtags * clean apply_diff * more cleaning * apply suggestions * Update proc-macro2, syn and quote to 1.0 CLOSES #590 * Fixed typo * Add support for optional callbacks to component properties * Add tests for a component with optional callback * Fix typo * Add `Classes` to prelude * added bincode type for data ser de * fixed Into func * Update (#5) * in yewstack org * Initial implementation using an iterator adaptor to provide a coherent struct to implement Into<VNode> (via From<>) for * update large table example to demonstrate new .html() method instead of 'for' * ran cargo fmt * Add a section for project templates to the README * Change org to YewStack * Implement FromIterator instead of wrapping iterator * remove dead code * ran fmt * Add extend method to Classes * change to union * renamed union back to extend * removed unused import of RangeFull * update * Fix touch events (#656) * Update changelog for v0.9 release (#657) * Implement Debug for ChildRenderer<T> (#655) * Implement Debug for ChildRenderer<T> * fix formatter type lifetime * remove fmt * cargo fmt * Emit initial route to router subscribers (#634) * Fix typo in RenderService (#658) * Add From<&String> for Classes implementation * @jstarry feedback - cargo fmt - rename DEDICATED_WORKERS_* to REMOTE_AGENTS_* - remove unrelated changes * TypeId ask key instead &str * Remove .gitignore changes * Update agent.rs * Update agent.rs * Fix merge conflict
* Update run instructions `python3 -m http.server --directory` flag was added in Python 3.7. Change instructions to cd into static and skip the flag instead - makes it work with earlier Pythons too. * Add visual feedback for button click The minimal example has a button, but clicking it does nothing. This makes it hard to tell whether the example works or not. This adds a label that is update when the button is clicked. * Small improvements to crm example * Add a heading to each scene to make it more obvious what the page is for. * Improve layout of input form by stack the inputs vertically. * Add a little space between entries when displaying the list. * Add a hint to the Description input that Markdown can be used. * Add an explanation to the file_upload example * Clarify purpose of var in fragments example * Improve futures_wp example * Add a second button that demonstrates an unsuccessful fetch. * Render the markdown document (since we're fetching markdown after all). * Remove vague comment that's not really helping. * Improve inner_html example * Include a textual explanation of what the example is doing. * Run cargo fmt * Remove 'static lifetime for constant * Improve suggestion in inner_html example * move markdown.rs to a common crate * add description to common Cargo.toml * PR feedback * PR feedback * remove static lifetime annotation
Consider to add
Component
trait to add JSX-style reusable components:The text was updated successfully, but these errors were encountered: