```rust extern crate kagura; extern crate wasm_bindgen;
use kagura::prelude::; use wasm_bindgen::prelude::;
pub fn main() { let node = websys::window() .unwrap() .document() .unwrap() .getelementbyid("app") .unwrap(); Kagura::mount(node.into(), || { vec![Html::h1( Attributes::new(), Events::new(), vec![Html::text("Hello Kagura")], )] }); } ```
See /project-template/^0.13
in this repogitory. This is a template of project of Kagura. You can custamize to use.
rust
Kagura::mount(web_sys::Node, impl FnMut() -> Vec<Html<Terminator>>)
Terminator
is a component, which is a marker of root of dom. And, Kagura only changes children of mounted web_sys::Node.
```rust use kagura::html::component::Cmd; use kagura::prelude::*;
// Property of component pub struct Props {}
// Message from Kagura to component pub enum Msg { Clicked, }
// Message from component to parent component // You can send message from child component to parent component by this. pub enum On {}
// Type of component // Also, this is component state too. pub struct MyComponent { greeting: String, }
// Settig Props, Msg and On to MyComponent. // (Sub means subscription.) impl Component for MyComponent { type Props = Props; type Msg = Msg; type Sub = On; }
impl Constructor for MyComponent { // Constructor of MyComponent. fn constructor(_props: &Self::Props) -> Self { Self { greeting: String::from("Hello world"), } } }
impl Update for MyComponent {
// The way to update MyComponent when MyComponent receive message.
// MyComponent can send some messgae to Kagura by Cmd
impl Render for MyComponent {
// The way to render MyComponent to Html
There are default-implemented function in Constructor trait.
Self
means the component which mounts to. DemirootComp
means the component which is mounted to.
```rust
fn with_children
fn with_child
fn empty
This is a example:
```rust extern crate jssys; extern crate kagura; extern crate wasmbindgen; extern crate web_sys;
use kagura::prelude::; use wasm_bindgen::prelude::;
mod my_component;
use my_component::MyComponent;
pub fn main() { Kagura::mount(entrypoint(), || { vec![MyComponent::empty( mycomponent::Props {}, component::Sub::none(), )] }); }
fn entrypoint() -> websys::Node { websys::window() .unwrap() .document() .unwrap() .getelementbyid("app") .unwrap() .into() }
```
This exmaple is mounting MyComponent to Terminator. And, in customed component, like MyComponent, you can do too in render. like this:
rust
impl Render for MyComponent {
fn render(&self, _props: &Props, _children: Vec<Html<Self>>) -> Html<Self> {
CustomedComponent::empty(
customed_component::Props {},
component::Sub::none(),
)
}
}