arch: split ConfigRepository, extract polling, consolidate conversions, decouple protocol
- Value↔JSON: From impls on domain Value behind `json` feature, delete 4 duplicate converters - ConfigRepository split into ConfigRepository (12), UserRepository (3), WidgetStateCache (2) - polling orchestration moved from bootstrap to application::polling_service - WidgetRenderer in client-domain owns scroll/cache, both clients use it - network loop consolidated into client-application::run_connection_loop - protocol crate drops domain dep, Wire↔Domain conversions move to adapters
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
use domain::value_objects::{
|
||||
AlignItems, ContainerNode, Direction, DisplayHint, DisplayHintKind, HAlign, JustifyContent,
|
||||
LayoutChild, LayoutNode, Sizing, VAlign, Value, WidgetError, WidgetState,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@@ -15,60 +11,12 @@ pub enum WireValue {
|
||||
Object(BTreeMap<String, WireValue>),
|
||||
}
|
||||
|
||||
impl From<&Value> for WireValue {
|
||||
fn from(v: &Value) -> Self {
|
||||
match v {
|
||||
Value::Null => WireValue::Null,
|
||||
Value::Bool(b) => WireValue::Bool(*b),
|
||||
Value::Number(n) => WireValue::Number(*n),
|
||||
Value::String(s) => WireValue::String(s.clone()),
|
||||
Value::Array(arr) => WireValue::Array(arr.iter().map(Into::into).collect()),
|
||||
Value::Object(map) => {
|
||||
WireValue::Object(map.iter().map(|(k, v)| (k.clone(), v.into())).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireValue> for Value {
|
||||
fn from(w: WireValue) -> Self {
|
||||
match w {
|
||||
WireValue::Null => Value::Null,
|
||||
WireValue::Bool(b) => Value::Bool(b),
|
||||
WireValue::Number(n) => Value::Number(n),
|
||||
WireValue::String(s) => Value::String(s),
|
||||
WireValue::Array(arr) => Value::Array(arr.into_iter().map(Into::into).collect()),
|
||||
WireValue::Object(map) => {
|
||||
Value::Object(map.into_iter().map(|(k, v)| (k, v.into())).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireWidgetError {
|
||||
SourceUnavailable,
|
||||
ExtractionFailed,
|
||||
}
|
||||
|
||||
impl From<&WidgetError> for WireWidgetError {
|
||||
fn from(e: &WidgetError) -> Self {
|
||||
match e {
|
||||
WidgetError::SourceUnavailable => WireWidgetError::SourceUnavailable,
|
||||
WidgetError::ExtractionFailed => WireWidgetError::ExtractionFailed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireWidgetError> for WidgetError {
|
||||
fn from(w: WireWidgetError) -> Self {
|
||||
match w {
|
||||
WireWidgetError::SourceUnavailable => WidgetError::SourceUnavailable,
|
||||
WireWidgetError::ExtractionFailed => WidgetError::ExtractionFailed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireKeyValue {
|
||||
pub key: String,
|
||||
@@ -81,35 +29,6 @@ pub struct WireWidgetState {
|
||||
pub error: Option<WireWidgetError>,
|
||||
}
|
||||
|
||||
impl From<&WidgetState> for WireWidgetState {
|
||||
fn from(s: &WidgetState) -> Self {
|
||||
WireWidgetState {
|
||||
data: s
|
||||
.data
|
||||
.iter()
|
||||
.map(|(k, v)| WireKeyValue {
|
||||
key: k.clone(),
|
||||
value: v.into(),
|
||||
})
|
||||
.collect(),
|
||||
error: s.error.as_ref().map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireWidgetState> for WidgetState {
|
||||
fn from(w: WireWidgetState) -> Self {
|
||||
WidgetState {
|
||||
data: w
|
||||
.data
|
||||
.into_iter()
|
||||
.map(|kv| (kv.key, kv.value.into()))
|
||||
.collect(),
|
||||
error: w.error.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireDisplayHintKind {
|
||||
IconValue,
|
||||
@@ -148,134 +67,18 @@ impl WireDisplayHint {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&DisplayHintKind> for WireDisplayHintKind {
|
||||
fn from(k: &DisplayHintKind) -> Self {
|
||||
match k {
|
||||
DisplayHintKind::IconValue => WireDisplayHintKind::IconValue,
|
||||
DisplayHintKind::TextBlock => WireDisplayHintKind::TextBlock,
|
||||
DisplayHintKind::KeyValue => WireDisplayHintKind::KeyValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireDisplayHintKind> for DisplayHintKind {
|
||||
fn from(w: WireDisplayHintKind) -> Self {
|
||||
match w {
|
||||
WireDisplayHintKind::IconValue => DisplayHintKind::IconValue,
|
||||
WireDisplayHintKind::TextBlock => DisplayHintKind::TextBlock,
|
||||
WireDisplayHintKind::KeyValue => DisplayHintKind::KeyValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&HAlign> for WireHAlign {
|
||||
fn from(h: &HAlign) -> Self {
|
||||
match h {
|
||||
HAlign::Left => WireHAlign::Left,
|
||||
HAlign::Center => WireHAlign::Center,
|
||||
HAlign::Right => WireHAlign::Right,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireHAlign> for HAlign {
|
||||
fn from(w: WireHAlign) -> Self {
|
||||
match w {
|
||||
WireHAlign::Left => HAlign::Left,
|
||||
WireHAlign::Center => HAlign::Center,
|
||||
WireHAlign::Right => HAlign::Right,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&VAlign> for WireVAlign {
|
||||
fn from(v: &VAlign) -> Self {
|
||||
match v {
|
||||
VAlign::Top => WireVAlign::Top,
|
||||
VAlign::Middle => WireVAlign::Middle,
|
||||
VAlign::Bottom => WireVAlign::Bottom,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireVAlign> for VAlign {
|
||||
fn from(w: WireVAlign) -> Self {
|
||||
match w {
|
||||
WireVAlign::Top => VAlign::Top,
|
||||
WireVAlign::Middle => VAlign::Middle,
|
||||
WireVAlign::Bottom => VAlign::Bottom,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&DisplayHint> for WireDisplayHint {
|
||||
fn from(h: &DisplayHint) -> Self {
|
||||
WireDisplayHint {
|
||||
kind: (&h.kind).into(),
|
||||
h_align: (&h.h_align).into(),
|
||||
v_align: (&h.v_align).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireDisplayHint> for DisplayHint {
|
||||
fn from(w: WireDisplayHint) -> Self {
|
||||
DisplayHint {
|
||||
kind: w.kind.into(),
|
||||
h_align: w.h_align.into(),
|
||||
v_align: w.v_align.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireSizing {
|
||||
Fixed(u16),
|
||||
Flex(u8),
|
||||
}
|
||||
|
||||
impl From<&Sizing> for WireSizing {
|
||||
fn from(s: &Sizing) -> Self {
|
||||
match s {
|
||||
Sizing::Fixed(px) => WireSizing::Fixed(*px),
|
||||
Sizing::Flex(w) => WireSizing::Flex(*w),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireSizing> for Sizing {
|
||||
fn from(w: WireSizing) -> Self {
|
||||
match w {
|
||||
WireSizing::Fixed(px) => Sizing::Fixed(px),
|
||||
WireSizing::Flex(weight) => Sizing::Flex(weight),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireDirection {
|
||||
Row,
|
||||
Column,
|
||||
}
|
||||
|
||||
impl From<&Direction> for WireDirection {
|
||||
fn from(d: &Direction) -> Self {
|
||||
match d {
|
||||
Direction::Row => WireDirection::Row,
|
||||
Direction::Column => WireDirection::Column,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireDirection> for Direction {
|
||||
fn from(w: WireDirection) -> Self {
|
||||
match w {
|
||||
WireDirection::Row => Direction::Row,
|
||||
WireDirection::Column => Direction::Column,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireJustifyContent {
|
||||
Start,
|
||||
@@ -285,30 +88,6 @@ pub enum WireJustifyContent {
|
||||
SpaceEvenly,
|
||||
}
|
||||
|
||||
impl From<&JustifyContent> for WireJustifyContent {
|
||||
fn from(j: &JustifyContent) -> Self {
|
||||
match j {
|
||||
JustifyContent::Start => WireJustifyContent::Start,
|
||||
JustifyContent::Center => WireJustifyContent::Center,
|
||||
JustifyContent::End => WireJustifyContent::End,
|
||||
JustifyContent::SpaceBetween => WireJustifyContent::SpaceBetween,
|
||||
JustifyContent::SpaceEvenly => WireJustifyContent::SpaceEvenly,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireJustifyContent> for JustifyContent {
|
||||
fn from(w: WireJustifyContent) -> Self {
|
||||
match w {
|
||||
WireJustifyContent::Start => JustifyContent::Start,
|
||||
WireJustifyContent::Center => JustifyContent::Center,
|
||||
WireJustifyContent::End => JustifyContent::End,
|
||||
WireJustifyContent::SpaceBetween => JustifyContent::SpaceBetween,
|
||||
WireJustifyContent::SpaceEvenly => JustifyContent::SpaceEvenly,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireAlignItems {
|
||||
Start,
|
||||
@@ -317,28 +96,6 @@ pub enum WireAlignItems {
|
||||
Stretch,
|
||||
}
|
||||
|
||||
impl From<&AlignItems> for WireAlignItems {
|
||||
fn from(a: &AlignItems) -> Self {
|
||||
match a {
|
||||
AlignItems::Start => WireAlignItems::Start,
|
||||
AlignItems::Center => WireAlignItems::Center,
|
||||
AlignItems::End => WireAlignItems::End,
|
||||
AlignItems::Stretch => WireAlignItems::Stretch,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireAlignItems> for AlignItems {
|
||||
fn from(w: WireAlignItems) -> Self {
|
||||
match w {
|
||||
WireAlignItems::Start => AlignItems::Start,
|
||||
WireAlignItems::Center => AlignItems::Center,
|
||||
WireAlignItems::End => AlignItems::End,
|
||||
WireAlignItems::Stretch => AlignItems::Stretch,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireContainerNode {
|
||||
pub direction: WireDirection,
|
||||
@@ -360,49 +117,3 @@ pub enum WireLayoutNode {
|
||||
Container(WireContainerNode),
|
||||
Leaf(u16),
|
||||
}
|
||||
|
||||
impl From<&LayoutNode> for WireLayoutNode {
|
||||
fn from(n: &LayoutNode) -> Self {
|
||||
match n {
|
||||
LayoutNode::Leaf(id) => WireLayoutNode::Leaf(*id),
|
||||
LayoutNode::Container(c) => WireLayoutNode::Container(WireContainerNode {
|
||||
direction: (&c.direction).into(),
|
||||
gap: c.gap,
|
||||
padding: c.padding,
|
||||
justify_content: (&c.justify_content).into(),
|
||||
align_items: (&c.align_items).into(),
|
||||
children: c
|
||||
.children
|
||||
.iter()
|
||||
.map(|ch| WireLayoutChild {
|
||||
sizing: (&ch.sizing).into(),
|
||||
node: (&ch.node).into(),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireLayoutNode> for LayoutNode {
|
||||
fn from(w: WireLayoutNode) -> Self {
|
||||
match w {
|
||||
WireLayoutNode::Leaf(id) => LayoutNode::Leaf(id),
|
||||
WireLayoutNode::Container(c) => LayoutNode::Container(ContainerNode {
|
||||
direction: c.direction.into(),
|
||||
gap: c.gap,
|
||||
padding: c.padding,
|
||||
justify_content: c.justify_content.into(),
|
||||
align_items: c.align_items.into(),
|
||||
children: c
|
||||
.children
|
||||
.into_iter()
|
||||
.map(|ch| LayoutChild {
|
||||
sizing: ch.sizing.into(),
|
||||
node: ch.node.into(),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user