Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ jobs:
run: cargo clippy --no-deps --target wasm32-unknown-unknown -- -Dwarnings
- name: Build | Compile
run: cargo build --target wasm32-unknown-unknown
- name: Build | Compile macros
run: cargo build -p yewdux-middleware-macros
4 changes: 3 additions & 1 deletion .github/workflows/publish-dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ jobs:
run: rustup default ${{ env.rust_toolchain }}
- name: Add wasm target
run: rustup target add wasm32-unknown-unknown
- name: Build | Publish Dry Run
- name: Build | Publish Dry Run macros
run: cargo publish --dry-run -p yewdux-middleware-macros
- name: Build | Publish Dry Run main crate
run: cargo publish --dry-run --target wasm32-unknown-unknown
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ jobs:
run: rustup target add wasm32-unknown-unknown
- name: Login
run: cargo login ${{ secrets.crates_io_token }}
- name: Build | Publish
- name: Build | Publish macros crate
run: cargo publish -p yewdux-middleware-macros
- name: Build | Publish main crate
run: cargo publish --target wasm32-unknown-unknown
- name: Get the crate version from cargo
run: |
Expand Down
48 changes: 48 additions & 0 deletions COPILOT_REMINDER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copilot CI Reminder

Before submitting any PR or pushing changes, always run the complete CI workflow locally to ensure the build passes:

## CI Steps (from `.github/workflows/ci.yml`)

1. **Format Check**
```bash
cargo fmt -- --check
```

2. **Add wasm target** (if not already added)
```bash
rustup target add wasm32-unknown-unknown
```

3. **Clippy (with warnings as errors)**
```bash
cargo clippy --no-deps --target wasm32-unknown-unknown -- -Dwarnings
```

4. **Build main crate**
```bash
cargo build --target wasm32-unknown-unknown
```

5. **Build macros crate**
```bash
cargo build -p yewdux-middleware-macros
```

## Quick Check Script

Run all CI steps in sequence:
```bash
cargo fmt -- --check && \
rustup target add wasm32-unknown-unknown && \
cargo clippy --no-deps --target wasm32-unknown-unknown -- -Dwarnings && \
cargo build --target wasm32-unknown-unknown && \
cargo build -p yewdux-middleware-macros
```

## Important Notes

- Always run these checks before committing
- Fix any warnings or errors before pushing
- The CI enforces `-Dwarnings` for clippy, so all warnings must be resolved
- Tests should also be run when making functional changes: `cargo test --lib`
22 changes: 21 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[workspace]
members = [".", "yewdux-middleware-macros"]

[package]
name = "yewdux-middleware"
version = "0.4.0"
Expand All @@ -10,7 +13,24 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
#forced-target = "wasm32-unknown-unknown"

[features]
default = ["future"]
future = []
doctests = []

[dependencies]
yewdux = { version = "0.11.0", default-features = false }
yew = { version = "0.22.0", default-features = false }
anymap2 = "0.13.0"

# === yewdux embedded dependencies (can be removed if switching back to external yewdux) ===
yewdux-middleware-macros = { path = "./yewdux-middleware-macros" }
log = "0.4.16"
serde = { version = "1.0.114", features = ["rc"] }
serde_json = "1.0.64"
slab = "0.4"
thiserror = "1.0"
web-sys = "0.3"
chrono = "0.4.22"
wasm-bindgen = "0.2"
# === end yewdux embedded dependencies ===

8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::rc::Rc;

pub mod yewdux;

pub use yewdux::prelude::{Reducer, Store};

pub use self::context::*;
Expand Down Expand Up @@ -46,8 +48,8 @@ where
mod context {
use std::rc::Rc;

use crate::yewdux::{mrc::Mrc, Context};
use anymap2::AnyMap;
use yewdux::{mrc::Mrc, Context};

use crate::MiddlewareDispatch;

Expand Down Expand Up @@ -87,8 +89,8 @@ mod context {

pub fn store<M, S>(&self, msg: M)
where
M: yewdux::prelude::Reducer<S>,
S: yewdux::prelude::Store,
M: crate::yewdux::prelude::Reducer<S>,
S: crate::yewdux::prelude::Store,
{
self.context.reduce(move |state| msg.apply(state));
}
Expand Down
37 changes: 37 additions & 0 deletions src/yewdux/anymap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::{
any::{Any, TypeId},
collections::HashMap,
};

#[derive(Default)]
pub(crate) struct AnyMap {
map: HashMap<TypeId, Box<dyn Any>>,
}

impl AnyMap {
pub(crate) fn entry<T: 'static>(&mut self) -> Entry<'_, T> {
Entry {
map: &mut self.map,
_marker: std::marker::PhantomData,
}
}
}

pub(crate) struct Entry<'a, T: 'static> {
map: &'a mut HashMap<TypeId, Box<dyn Any>>,
_marker: std::marker::PhantomData<T>,
}

impl<'a, T: 'static> Entry<'a, T> {
pub(crate) fn or_insert_with<F>(self, default: F) -> &'a mut T
where
F: FnOnce() -> T,
{
let type_id = TypeId::of::<T>();
let value = self
.map
.entry(type_id)
.or_insert_with(|| Box::new(default()));
value.downcast_mut().expect("type id mismatch")
}
}
Loading