♻️ Use of Store interfaces
This commit is contained in:
@@ -1,24 +1,50 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
use crate::domain::model::{space::SpaceId, store_interface::SpaceStoreProviderInterface};
|
||||
use crate::domain::model::{
|
||||
space::SpaceId,
|
||||
store_interface::{SpaceStoreConsumerInterface, SpaceStoreProviderInterface},
|
||||
};
|
||||
|
||||
#[modx::props(id, name)]
|
||||
#[modx::store]
|
||||
pub struct Space {
|
||||
pub struct Store {
|
||||
id: SpaceId,
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
impl PartialEq for Space {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
#[derive(Clone)]
|
||||
pub struct Space {
|
||||
store: RefCell<Store>,
|
||||
domain: Rc<dyn SpaceStoreConsumerInterface>,
|
||||
}
|
||||
|
||||
impl Space {
|
||||
pub fn signal(&self) -> Store {
|
||||
self.store.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn from_domain(space: Rc<dyn SpaceStoreConsumerInterface>) -> Self {
|
||||
let props = StoreProps::new(space.id().clone(), space.name());
|
||||
|
||||
Self {
|
||||
store: RefCell::new(Store::new(props)),
|
||||
domain: space,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SpaceStoreProviderInterface for RefCell<Space> {
|
||||
fn set_name(&self, name: Option<String>) {
|
||||
self.borrow_mut().name.set(name);
|
||||
impl PartialEq for Space {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.store.borrow().id == other.store.borrow().id
|
||||
}
|
||||
}
|
||||
|
||||
impl SpaceStoreProviderInterface for Space {
|
||||
fn set_name(&self, name: Option<String>) {
|
||||
let mut store = self.store.borrow_mut();
|
||||
store.name.set(name);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user