Skip to content

Commit

Permalink
Merge pull request #46 from jamsocket/paulgb/add-aper-leptos
Browse files Browse the repository at this point in the history
Add aper-leptos
  • Loading branch information
paulgb authored Oct 5, 2024
2 parents 9783bc8 + 093b9ec commit 6475771
Show file tree
Hide file tree
Showing 10 changed files with 1,334 additions and 315 deletions.
1,241 changes: 1,082 additions & 159 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ exclude = [
]

members = [
"aper",
"aper/aper-derive*",
"aper-websocket-client",
"aper-leptos",
"aper-serve",
"aper-stateroom",
"site/doctests", "aper-yew",
"aper-websocket-client",
"aper-yew",
"aper",
"aper/aper-derive*",
"site/doctests",
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Aper supports optimistic updates and arbitrary business logic, making it useful

## Introduction

(More docs coming soon, [peek at a WIP here](https://github.com/jamsocket/aper/tree/main/site/book/src))
**(Aper is mid-refactor. Docs and examples may be out of date.)**

Types marked with the `AperSync` trait can be stored in the `Store`, Aper's synchronizable data store.
Aper includes several data structures that implement `AperSync` in the `aper::data_structures` module, which
Expand Down
12 changes: 12 additions & 0 deletions aper-leptos/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "aper-leptos"
version = "0.5.0"
edition = "2021"

[dependencies]
aper = {path = "../aper"}
aper-websocket-client = { version="0.5.0", path="../aper-websocket-client" }
leptos = { version = "0.6.14", features = ["csr"] }
serde = "1.0.210"
tracing-subscriber = "0.3.18"
tracing-web = "0.1.3"
File renamed without changes.
26 changes: 26 additions & 0 deletions aper-leptos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use aper::{data_structures::Atom, AperSync};
use leptos::{create_signal, ReadSignal, SignalSet};
use serde::{de::DeserializeOwned, Serialize};

pub mod init_tracing;

pub trait Watch<T> {
fn watch(&self) -> ReadSignal<T>;
}

impl<T> Watch<T> for Atom<T>
where
T: Serialize + DeserializeOwned + Default + Clone + Send + Sync + 'static,
{
fn watch(&self) -> ReadSignal<T> {
let (signal, set_signal) = create_signal(self.get());

let self_clone = self.clone();
self.listen(move || {
set_signal.set(self_clone.get());
true
});

signal
}
}
Loading

0 comments on commit 6475771

Please sign in to comment.