feat: amazingly awesome error handling
This commit is contained in:
1 parent
05c909f320
commit
4a72b3140b
58 files changed
+248
-1219
No files matched your search
@@ -82,7 +82,7 @@ fn main() {
|
||||
dioxus::web::start(App)
|
||||
}
|
||||
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
fn App(cx: Context<()>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div { "Hello, world!" }
|
||||
})
|
||||
@@ -108,7 +108,7 @@ fn main() {
|
||||
Finally, our app. Every component in Dioxus is a function that takes in a `Context` object and returns a `VNode`.
|
||||
|
||||
```rust
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
fn App(cx: Context<()>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div { "Hello, world!" }
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ You'll want to write RSX where you can, and in a future release we'll have a too
|
||||
#[derive(PartialEq, Props)]
|
||||
struct ExampleProps { name: &str, pending: bool, count: i32 }
|
||||
|
||||
fn Example(cx: Context<ExampleProps> ) -> VNode {
|
||||
fn Example(cx: Context<ExampleProps> ) -> DomTree {
|
||||
let ExampleProps { name, pending, count } = cx.props;
|
||||
cx.render(html! {
|
||||
<div>
|
||||
@@ -35,7 +35,7 @@ The Dioxus VSCode extension will eventually provide a macro to convert a selecti
|
||||
It's also a bit easier on the eyes 🙂 than HTML.
|
||||
|
||||
```rust
|
||||
fn Example(cx: Context<ExampleProps>) -> VNode {
|
||||
fn Example(cx: Context<ExampleProps>) -> DomTree {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
// cx derefs to props so you can access fields directly
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
```rust
|
||||
fn Example(cx: &mut Context<()>) -> VNode {
|
||||
fn Example(cx: &mut Context<()>) -> DomTree {
|
||||
let service = use_combubulator(cx);
|
||||
let Status { name, pending, count } = service.info();
|
||||
html! {
|
||||
|
||||
@@ -5,19 +5,19 @@
|
||||
// Only one context can be associated with any given component
|
||||
// This is known as "exposed state". Children can access this context,
|
||||
// but will not be automatically subscribed.
|
||||
fn ContextCreate(cx: &mut Context<()>) -> VNode {
|
||||
fn ContextCreate(cx: &mut Context<()>) -> DomTree {
|
||||
let context = cx.set_context(|| CustomContext::new());
|
||||
html! { <> {cx.children()} </> }
|
||||
}
|
||||
|
||||
fn ContextRead(cx: &mut Context<()>) -> VNode {
|
||||
fn ContextRead(cx: &mut Context<()>) -> DomTree {
|
||||
// Panics if context is not available
|
||||
let some_cx = cx.get_context::<CustomContext>();
|
||||
let text = some_cx.select("some_selector");
|
||||
html! { <div> "{text}" </div> }
|
||||
}
|
||||
|
||||
fn Subscription(cx: &mut Context<()>) -> VNode {
|
||||
fn Subscription(cx: &mut Context<()>) -> DomTree {
|
||||
// Open a "port" on the component for actions to trigger a re-evaluation
|
||||
let subscription = cx.new_subscription();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Yew subscriptions are used to schedule update for components into the future. The `Context` object can create subscriptions:
|
||||
|
||||
```rust
|
||||
fn Component(cx: Component<()>) -> VNode {
|
||||
fn Component(cx: Component<()>) -> DomTree {
|
||||
let update = cx.schedule();
|
||||
|
||||
// Now, when the subscription is called, the component will be re-evaluted
|
||||
|
||||
@@ -62,7 +62,7 @@ async fn ExampleLoader(cx: Context<()>) -> Vnode {
|
||||
```
|
||||
|
||||
```rust
|
||||
async fn Example(cx: Context<()>) -> VNode {
|
||||
async fn Example(cx: Context<()>) -> DomTree {
|
||||
// Diff this set between the last set
|
||||
// Check if we have any outstanding tasks?
|
||||
//
|
||||
|
||||
@@ -11,7 +11,7 @@ https://dmitripavlutin.com/use-react-memo-wisely/
|
||||
This behavior is defined as an implicit attribute to user components. When in React land you might wrap a component is `react.memo`, Dioxus components are automatically memoized via an implicit attribute. You can manually configure this behavior on any component with "nomemo" to disable memoization.
|
||||
|
||||
```rust
|
||||
fn test() -> VNode {
|
||||
fn test() -> DomTree {
|
||||
html! {
|
||||
<>
|
||||
<SomeComponent nomemo />
|
||||
@@ -41,7 +41,7 @@ static TestComponent: FC<{ name: String }> = |cx| html! { <div> "Hello {name}" <
|
||||
Take a component likes this:
|
||||
|
||||
```rust
|
||||
fn test(cx: Context<()>) -> VNode {
|
||||
fn test(cx: Context<()>) -> DomTree {
|
||||
let Bundle { alpha, beta, gamma } = use_context::<SomeContext>(cx);
|
||||
html! {
|
||||
<div>
|
||||
|
||||
@@ -11,7 +11,7 @@ By default, Dioxus will only try to diff subtrees of components with dynamic con
|
||||
Your component today might look something like this:
|
||||
|
||||
```rust
|
||||
fn Comp(cx: Context<()>) -> VNode {
|
||||
fn Comp(cx: Context<()>) -> DomTree {
|
||||
let (title, set_title) = use_state(cx, || "Title".to_string());
|
||||
cx.render(rsx!{
|
||||
input {
|
||||
@@ -25,7 +25,7 @@ fn Comp(cx: Context<()>) -> VNode {
|
||||
This component is fairly straightforward - the input updates its own value on every change. However, every call to set_title will re-render the component. If we add a large list, then every time we update the title input, Dioxus will need to diff the entire list, over, and over, and over. This is **a lot** of wasted clock-cycles!
|
||||
|
||||
```rust
|
||||
fn Comp(cx: Context<()>) -> VNode {
|
||||
fn Comp(cx: Context<()>) -> DomTree {
|
||||
let (title, set_title) = use_state(cx, || "Title".to_string());
|
||||
cx.render(rsx!{
|
||||
div {
|
||||
@@ -48,7 +48,7 @@ Many experienced React developers will just say "this is bad design" - but we co
|
||||
We can use signals to generate a two-way binding between data and the input box. Our text input is now just a two-line component!
|
||||
|
||||
```rust
|
||||
fn Comp(cx: Context<()>) -> VNode {
|
||||
fn Comp(cx: Context<()>) -> DomTree {
|
||||
let mut title = use_signal(&cx, || String::from("Title"));
|
||||
cx.render(rsx!(input { value: title }))
|
||||
}
|
||||
@@ -57,7 +57,7 @@ fn Comp(cx: Context<()>) -> VNode {
|
||||
For a slightly more interesting example, this component calculates the sum between two numbers, but totally skips the diffing process.
|
||||
|
||||
```rust
|
||||
fn Calculator(cx: Context<()>) -> VNode {
|
||||
fn Calculator(cx: Context<()>) -> DomTree {
|
||||
let mut a = use_signal(&cx, || 0);
|
||||
let mut b = use_signal(&cx, || 0);
|
||||
let mut c = a + b;
|
||||
|
||||
@@ -8,7 +8,7 @@ struct MyProps {
|
||||
name: String
|
||||
}
|
||||
|
||||
fn Example(cx: Context<MyProps>) -> VNode {
|
||||
fn Example(cx: Context<MyProps>) -> DomTree {
|
||||
cx.render(html! {
|
||||
<div> "Hello {cx.name}!" </div>
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
In Dioxus, VNodes are asynchronous and can their rendering can be paused at any time by awaiting a future. Hooks can combine this functionality with the Context and Subscription APIs to craft dynamic and efficient user experiences.
|
||||
|
||||
```rust
|
||||
fn user_data(cx: Context<()>) -> VNode {
|
||||
fn user_data(cx: Context<()>) -> DomTree {
|
||||
// Register this future as a task
|
||||
use_suspense(cx, async {
|
||||
// Continue on with the component as usual, waiting for data to arrive
|
||||
|
||||
@@ -5,7 +5,7 @@ With the Context, Subscription, and Asynchronous APIs, we've built Dioxus Livevi
|
||||
These set of features are still experimental. Currently, we're still working on making these components more ergonomic
|
||||
|
||||
```rust
|
||||
fn live_component(cx: &Context<()>) -> VNode {
|
||||
fn live_component(cx: &Context<()>) -> DomTree {
|
||||
use_live_component(
|
||||
cx,
|
||||
// Rendered via the client
|
||||
|
||||
@@ -8,7 +8,7 @@ struct MyProps {
|
||||
name: String
|
||||
}
|
||||
|
||||
fn Example(cx: Context<MyProps>) -> VNode {
|
||||
fn Example(cx: Context<MyProps>) -> DomTree {
|
||||
html! { <div> "Hello {cx.cx.name}!" </div> }
|
||||
}
|
||||
```
|
||||
@@ -18,7 +18,7 @@ Here, the `Context` object is used to access hook state, create subscriptions, a
|
||||
```rust
|
||||
// A very terse component!
|
||||
#[fc]
|
||||
fn Example(cx: Context, name: String) -> VNode {
|
||||
fn Example(cx: Context, name: String) -> DomTree {
|
||||
html! { <div> "Hello {name}!" </div> }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user