Component

Derive Macro Component 

Source
#[derive(Component)]
{
    // Attributes available to this derive:
    #[component]
    #[state]
    #[prop]
    #[event]
}
Expand description

Derive macro for creating Angular-like components.

This macro generates the component infrastructure including state management, property binding, event emission, and lifecycle hooks.

§Attributes

  • #[component(selector = "...")] - Set the component selector
  • #[state] - Mark a field as reactive state
  • #[prop] - Mark a field as a component property
  • #[prop(default = value)] - Property with default value
  • #[event] - Mark a field as an event emitter

§Example

use openkit_macros::Component;

#[derive(Component)]
#[component(selector = "counter")]
struct Counter {
    #[state]
    count: i32,

    #[prop(default = 1)]
    step: i32,

    #[event]
    on_change: EventEmitter<i32>,
}

impl Counter {
    fn increment(&mut self) {
        self.count += self.step;
        self.on_change.emit(self.count);
    }
}