Struct consecuit::construction::component::ComponentConstruction[][src]

pub struct ComponentConstruction<CurrentStores: StoresList, EntireStores: StoresList, LastNode: MaybeHoleNode, ReturnNode: MaybeHoleNode> { /* fields omitted */ }
Expand description

This is the consecuit or cc object in your component function.

You can use it to call hooks and render other components.

See the doc at crate on how to write components.

Implementations

Mark this component as a base container component.

This is for creating your own base component.

If you stick with the ones provided by the consecuit_html crate, you won’t need this.

Look at consecuit_html’s source code for example on how to create base components.

Note that when creating base components, you are stepping outside the “functional” model, and some rules apply:

  • Nodes should be created on initial render.
  • You can create nodes in later renders, but they must be descendant of the nodes created on initial render.
  • The node you pass to bare_container_node should be the same node in all render.

Mark this component as a base leaf (childless) component.

This is for creating your own base component.

If you stick with the ones provided by the consecuit_html crate, you won’t need this. Look at consecuit_html’s source code for example on how to create base components.

Note that when creating base components, you are stepping outside the “functional” model, and some rules apply:

  • Nodes should be created on initial render.
  • You can create nodes in later renders, but they must be descendant of the nodes created on initial render.

Get the parent Node the current component should render on.

This is for creating your own base component. If you stick with the ones provided by the consecuit_html crate, you won’t need this.

If you want to use this, use consecuit_html’s source code as example.

Use the given hook, with the given arg.

Consumes self. Returns a tuple of (cc, <return value of hook>). You can use the returned cc to call more hooks.

See the docs at crate for more info on how to write and use hooks.

Render the given component with the given prop.

This consumes the consecuit or cc object, and returns a new one.

This is equivalent to a tag in the cc_tree! macro.

For example:

cc_tree!(
    <div />
    <footer {html_props().class_name("hi")} />
)

is equivalent to

cc.comp(div, Default::default())
    .comp(footer, html_props().class_name("hi"))

Descend into the hole of the last component with the given closure.

This consumes the consecuit or cc object, and returns a new one.

Use this to nest components. For example:

cc.comp(table, html_props())
    .child(|cc| {
        cc.comp(tr, html_props())
        .child(|cc| {
            cc.comp(td, html_props())
            .child(|cc| {
                cc.comp(text_node, "hello")
            })
        })
    })

The cc_tree! macro equivalent for the above code is:

cc_tree!(
    <table {html_props()}>
        <tr {html_props()}>
            <td {html_props()}>
                "hello"
            </td>
        </tr>
    </table>
)

Some restrictions:

  • This only work on components that returns impl ContainerReturn.
  • You can only use this once per component. cc.comp(...).child(...).child(...) is not valid.
  • This is mutaully exclusive with .hole_here(). cc.comp(...).hole_here().child(...) is not valid.

Mark the lastest comp as the Hole of this component.

Calling .child(...) on this component will put the children there.

A component that returns impl ContainerReturn must have exactly one .hole_here().

The cc_tree! macro equivalent to this is the HOLE attribute. Like <div HOLE />

Like .comp(...), but mount the component in a dynamic subtree.

This hides the components’ typing from its parent.

You can use this to name a component’s return type concretely.

The task is a bit boilerplatey. Copy paste this code:

fn outer_comp(cc: ComponentBuilder, props: MyProp) -> DynComponentReturn<MyProp> {
    fn inner_comp(cc: ComponentBuilder, props: MyProp) -> impl ComponentReturn {
        cc_tree!(
            <div>
                "hello, I'm a dynamic component. My props is:"
                {props.to_string()}
            </div>
        )
    }
    let cc = cc.init(); // Initialize the component. `.hook(...)` and `.comp(...)` automatically does this, but `.dyn_comp(...)` doesn't.
    cc.dyn_comp(inner_comp, props)
    // inner_comp doesn't have to be an inner function. a closure works too (but it must be a non-capturing closure).
}

Then modify inner_comp as you like.

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.