Skip to content

Commit

Permalink
Put derive uniffi in application
Browse files Browse the repository at this point in the history
  • Loading branch information
Almaju committed Jan 30, 2024
1 parent cc0af95 commit 8a76e8f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 42 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions application/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ edition = "2021"
domain = { path = "../domain" }
framework = { path = "../crates/framework" }
serde = { version = "1.0", features = ["derive"] }
uniffi = { version = "0.25.3" }
4 changes: 2 additions & 2 deletions application/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use serde::Deserialize;
#[derive(Deserialize)]
pub enum Command {
AddTask { name: String },
RemoveTask { index: usize },
CompleteTask { index: usize },
RemoveTask { index: u32 },
CompleteTask { index: u32 },
}

#[derive(Debug, Error)]
Expand Down
2 changes: 2 additions & 0 deletions application/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ pub mod port;
pub mod projection;
pub mod query;
pub mod snapshot;

uniffi::setup_scaffolding!();
8 changes: 4 additions & 4 deletions application/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ use domain::todolist_event::TodoListEvent;
use framework::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, Serialize, Deserialize)]
#[derive(Clone, Default, Debug, Serialize, Deserialize, uniffi::Record)]
pub struct TodoList {
pub tasks: Vec<Task>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, uniffi::Record)]
pub struct Task {
pub index: usize,
pub index: u32,
pub name: String,
pub status: TaskStatus,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, uniffi::Enum)]
pub enum TaskStatus {
Created,
Completed,
Expand Down
26 changes: 2 additions & 24 deletions clients/mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use application::command::Command;
use application::projection::TodoList;
use application::query::GetTodoListQuery;
use framework::*;
use std::collections::HashMap;
use std::sync::Arc;

mod runtime;
Expand Down Expand Up @@ -31,28 +30,7 @@ impl Client {
}

pub async fn get_todolist(&self) -> TodoList {
GetTodoListQuery {}
.execute(&self.runtime)
.await
.unwrap()
.into()
GetTodoListQuery {}.execute(&self.runtime).await.unwrap();
todo!()
}
}

#[derive(uniffi::Object)]
struct TodoList {
pub in_progress: HashMap<u32, String>,
pub completed: HashMap<u32, String>,
}

impl From<TodoList> for TodoList {
fn from(projection: TodoList) -> Self {
Self {
in_progress: projection.in_progress,
completed: projection.completed,
}
}
}

// #[uniffi::export]
// pub struct Query(GetTodoListQuery);
19 changes: 11 additions & 8 deletions clients/yew/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
mod runtime;

use application::{command::Command, projection::TodoList};
use application::{
command::Command,
projection::{TaskStatus, TodoList},
};
use framework::*;
use runtime::Runtime;
use web_sys::HtmlInputElement;
Expand Down Expand Up @@ -62,7 +65,7 @@ fn App() -> Html {
let fetch = fetch.clone();
let runtime = runtime.clone();

Callback::from(move |index: usize| {
Callback::from(move |index| {
let fetch = fetch.clone();
let runtime = runtime.clone();

Expand All @@ -84,7 +87,7 @@ fn App() -> Html {
let fetch = fetch.clone();
let runtime = runtime.clone();

Callback::from(move |index: usize| {
Callback::from(move |index| {
let fetch = fetch.clone();
let runtime = runtime.clone();

Expand All @@ -107,9 +110,9 @@ fn App() -> Html {
<h1>{ "Todo List" }</h1>
<h2>{ "In Progress" }</h2>
<ul>
{todo_list.clone().in_progress.iter().map(|task| {
let task_index = *task.0;
let task_name = task.1.clone();
{todo_list.clone().tasks.iter().filter(|task| task.status == TaskStatus::Created).map(|task| {
let task_index = task.index;
let task_name = task.name.clone();
let complete_task = complete_task.clone().reform(move |_| task_index);
let remove_task = remove_task.clone().reform(move |_| task_index);

Expand All @@ -123,8 +126,8 @@ fn App() -> Html {
}).collect::<Html>()}
</ul>
<h2>{ "Completed" }</h2>
{todo_list.clone().completed.values().map(|task_name| html! {
<li><input type="checkbox" checked={true} disabled={true} /> { &task_name }</li>
{todo_list.clone().tasks.iter().filter(|task| task.status == TaskStatus::Completed).map(|task| html! {
<li><input type="checkbox" checked={true} disabled={true} /> { &task.name }</li>
}).collect::<Html>()}
<input ref={input_ref} type="text" id="task" name="task" />
<button onclick={add_task}>{ "Add Task" }</button>
Expand Down
2 changes: 1 addition & 1 deletion domain/src/todolist_saga.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{todolist_event::TodoListEvent, todolist_scalar::TaskIndex};

pub struct TodoListSaga<'a>(pub &'a [TodoListEvent]);
pub(crate) struct TodoListSaga<'a>(pub &'a [TodoListEvent]);

pub(crate) enum TaskStatus {
None,
Expand Down
6 changes: 3 additions & 3 deletions domain/src/todolist_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use framework::*;
use serde::{Deserialize, Serialize};

#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub struct TaskIndex(pub usize);
pub struct TaskIndex(pub u32);

impl From<&usize> for TaskIndex {
fn from(value: &usize) -> Self {
impl From<&u32> for TaskIndex {
fn from(value: &u32) -> Self {
Self(*value)
}
}
Expand Down

0 comments on commit 8a76e8f

Please sign in to comment.