Skip to main content

Store

Derive Macro Store 

Source
#[derive(Store)]
Expand description

Derive macro for the Store trait

Automatically implements the Store trait for structs.

§Requirements

Your struct must derive Default. The macro will implement the Store trait using the struct’s type name as the store identifier.

§Example

use revue::prelude::*;
use revue_macros::Store;

#[derive(Store, Default)]
struct CounterStore {
    count: Signal<i32>,
}

impl CounterStore {
    fn new() -> Self {
        Self {
            count: signal(0),
        }
    }

    fn increment(&self) {
        self.count.update(|c| *c += 1);
    }
}

// Use the store
let counter = use_store::<CounterStore>();
counter.increment();

§Generated Implementation

The macro generates:

  • id() method that returns a unique ID based on the type name
  • name() method that returns the struct name
  • get_state() and get_getters() methods (basic implementations)