Skip to content

Commit 079c295

Browse files
committed
feat!: features of frender-dom-tokens
1 parent 7304d04 commit 079c295

File tree

30 files changed

+1007
-700
lines changed

30 files changed

+1007
-700
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/frender-dom-tokens/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
async-str-iter = { version = "0.1.0", path = "../async-str-iter", default-features = false }
109
either = { version = "1.11.0", default-features = false, optional = true }
1110
frender-common = { version = "0.1.0", path = "../frender-common" }
12-
frender-const = { version = "0.1.0", path = "../frender-const", features = ["KnownConstUsizeAdd"] }
11+
frender-const = { version = "0.1.0", path = "../frender-const", features = [
12+
"KnownConstUsizeAdd",
13+
] }
1314
frender-const-expr = { version = "0.1.0", path = "../frender-const-expr" }
1415
frender-macro-rules = { version = "0.1.0", path = "../frender-macro-rules", features = [
1516
"define_phantom_wrapper",
1617
] }
18+
frender-reactive-value = { version = "0.1.0", path = "../frender-reactive-value" }
1719
web-sys = { version = "0.3.69", features = ["DomTokenList"], optional = true }
1820

21+
# ssr
22+
async-str-iter = { version = "0.1.0", path = "../async-str-iter", default-features = false, optional = true }
23+
1924
[dev-dependencies]
2025
futures-lite = "2.3.0"
2126

2227
[features]
28+
csr = []
29+
ssr = ["dep:async-str-iter", "frender-reactive-value/ssr"]
2330
# impl DomTokens, ChainableDomTokens for Either
2431
either = ["dep:either"]
2532
# impl DomTokenList for web_sys::DomTokenList
2633
web = ["dep:web-sys"]
34+
experimental = []

packages/frender-dom-tokens/src/chain.rs

Lines changed: 120 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use frender_const::{ConstUsize, KnownConstUsizeAdd};
33
use crate::{
44
constness::{HasConstKnownPossibleDomTokens, IsConstUsize},
55
dom_token::UniqueDomTokenArrayVec,
6-
ChainableDomTokens, DomTokens, DomTokensStateUnmount,
6+
ChainableDomTokens, DomTokens,
77
};
88

99
#[derive(Debug, Clone, Copy)]
@@ -24,85 +24,25 @@ where
2424
};
2525
}
2626

27-
impl<A: DomTokensStateUnmount, B: DomTokensStateUnmount> DomTokensStateUnmount for (A, B) {
28-
fn dom_tokens_state_unmount(
29-
(state_a, state_b): &mut Self,
30-
dom_token_list: &mut impl crate::DomTokenList,
31-
) {
32-
A::dom_tokens_state_unmount(state_a, dom_token_list);
33-
B::dom_tokens_state_unmount(state_b, dom_token_list);
34-
}
27+
impl<A: ChainableDomTokens, B: ChainableDomTokens> crate::sealed::DomTokens for Chain<A, B> where
28+
Self: HasConstKnownPossibleDomTokens
29+
{
3530
}
3631

37-
impl<A: ChainableDomTokens, B: ChainableDomTokens> DomTokens for Chain<A, B>
38-
where
39-
Self: HasConstKnownPossibleDomTokens,
32+
impl<A: ChainableDomTokens, B: ChainableDomTokens> DomTokens for Chain<A, B> where
33+
Self: HasConstKnownPossibleDomTokens
4034
{
41-
type State = (A::State, B::State);
42-
43-
fn dom_tokens_render_init(
44-
Self(a, b): Self,
45-
dom_token_list: &mut impl crate::DomTokenList,
46-
) -> Self::State {
47-
_ = Self::ASSERT_KNOWN_NOT_DUP;
48-
(
49-
A::dom_tokens_render_init(a, dom_token_list),
50-
B::dom_tokens_render_init(b, dom_token_list),
51-
)
52-
}
53-
54-
fn dom_tokens_render_init_with_old_state(
55-
Self(a, b): Self,
56-
dom_token_list: &mut impl crate::DomTokenList,
57-
(old_state_a, old_state_b): &mut Self::State,
58-
) {
59-
_ = Self::ASSERT_KNOWN_NOT_DUP;
60-
A::dom_tokens_render_init_with_old_state(a, dom_token_list, old_state_a);
61-
B::dom_tokens_render_init_with_old_state(b, dom_token_list, old_state_b);
62-
}
63-
64-
fn dom_tokens_render_update(
65-
Self(a, b): Self,
66-
dom_token_list: &mut impl crate::DomTokenList,
67-
(state_a, state_b): &mut Self::State,
68-
) {
69-
_ = Self::ASSERT_KNOWN_NOT_DUP;
70-
A::dom_tokens_render_update(a, dom_token_list, state_a);
71-
B::dom_tokens_render_update(b, dom_token_list, state_b);
72-
}
73-
74-
type DomTokensIntoAsyncStrIter = async_str_iter::chain::Chain<
75-
A::DomTokensIntoAsyncStrIter,
76-
B::DomTokensPrefixSpaceIntoAsyncStrIter,
77-
>;
78-
79-
fn dom_tokens_into_async_str_iter(Self(a, b): Self) -> Self::DomTokensIntoAsyncStrIter {
80-
_ = Self::ASSERT_KNOWN_NOT_DUP;
81-
async_str_iter::chain::Chain::new(
82-
A::dom_tokens_into_async_str_iter(a),
83-
B::dom_tokens_prefix_space_into_async_str_iter(b),
84-
)
85-
}
8635
}
8736

88-
impl<A: ChainableDomTokens, B: ChainableDomTokens> ChainableDomTokens for Chain<A, B>
37+
impl<A: ChainableDomTokens, B: ChainableDomTokens> crate::sealed::ChainableDomTokens
38+
for crate::Chain<A, B>
8939
where
9040
Self: HasConstKnownPossibleDomTokens,
9141
{
92-
type DomTokensPrefixSpaceIntoAsyncStrIter = async_str_iter::chain::Chain<
93-
A::DomTokensPrefixSpaceIntoAsyncStrIter,
94-
B::DomTokensPrefixSpaceIntoAsyncStrIter,
95-
>;
96-
97-
fn dom_tokens_prefix_space_into_async_str_iter(
98-
Self(a, b): Self,
99-
) -> Self::DomTokensPrefixSpaceIntoAsyncStrIter {
100-
_ = Self::ASSERT_KNOWN_NOT_DUP;
101-
async_str_iter::chain::Chain::new(
102-
A::dom_tokens_prefix_space_into_async_str_iter(a),
103-
B::dom_tokens_prefix_space_into_async_str_iter(b),
104-
)
105-
}
42+
}
43+
impl<A: ChainableDomTokens, B: ChainableDomTokens> ChainableDomTokens for Chain<A, B> where
44+
Self: HasConstKnownPossibleDomTokens
45+
{
10646
}
10747

10848
impl<
@@ -126,3 +66,111 @@ where
12666
)
12767
};
12868
}
69+
70+
#[cfg(feature = "csr")]
71+
mod csr {
72+
use crate::{
73+
constness::HasConstKnownPossibleDomTokens,
74+
csr::{CsrDomTokens, DomTokenList, DomTokensStateUnmount},
75+
ChainableDomTokens,
76+
};
77+
78+
use super::Chain;
79+
80+
impl<A: DomTokensStateUnmount, B: DomTokensStateUnmount> DomTokensStateUnmount for (A, B) {
81+
fn dom_tokens_state_unmount(
82+
(state_a, state_b): &mut Self,
83+
dom_token_list: &mut impl DomTokenList,
84+
) {
85+
A::dom_tokens_state_unmount(state_a, dom_token_list);
86+
B::dom_tokens_state_unmount(state_b, dom_token_list);
87+
}
88+
}
89+
90+
impl<A: ChainableDomTokens, B: ChainableDomTokens> CsrDomTokens for Chain<A, B>
91+
where
92+
Self: HasConstKnownPossibleDomTokens,
93+
{
94+
type State = (A::State, B::State);
95+
96+
fn dom_tokens_render_init(
97+
Self(a, b): Self,
98+
dom_token_list: &mut impl DomTokenList,
99+
) -> Self::State {
100+
_ = Self::ASSERT_KNOWN_NOT_DUP;
101+
(
102+
A::dom_tokens_render_init(a, dom_token_list),
103+
B::dom_tokens_render_init(b, dom_token_list),
104+
)
105+
}
106+
107+
fn dom_tokens_render_init_with_old_state(
108+
Self(a, b): Self,
109+
dom_token_list: &mut impl DomTokenList,
110+
(old_state_a, old_state_b): &mut Self::State,
111+
) {
112+
_ = Self::ASSERT_KNOWN_NOT_DUP;
113+
A::dom_tokens_render_init_with_old_state(a, dom_token_list, old_state_a);
114+
B::dom_tokens_render_init_with_old_state(b, dom_token_list, old_state_b);
115+
}
116+
117+
fn dom_tokens_render_update(
118+
Self(a, b): Self,
119+
dom_token_list: &mut impl DomTokenList,
120+
(state_a, state_b): &mut Self::State,
121+
) {
122+
_ = Self::ASSERT_KNOWN_NOT_DUP;
123+
A::dom_tokens_render_update(a, dom_token_list, state_a);
124+
B::dom_tokens_render_update(b, dom_token_list, state_b);
125+
}
126+
}
127+
}
128+
129+
#[cfg(feature = "ssr")]
130+
mod ssr {
131+
use crate::{
132+
constness::HasConstKnownPossibleDomTokens,
133+
ssr::{SsrChainableDomTokens, SsrDomTokens},
134+
ChainableDomTokens,
135+
};
136+
137+
use super::Chain;
138+
139+
impl<A: ChainableDomTokens, B: ChainableDomTokens> SsrDomTokens for Chain<A, B>
140+
where
141+
Self: HasConstKnownPossibleDomTokens,
142+
{
143+
type DomTokensIntoAsyncStrIter = async_str_iter::chain::Chain<
144+
A::DomTokensIntoAsyncStrIter,
145+
B::DomTokensPrefixSpaceIntoAsyncStrIter,
146+
>;
147+
148+
fn dom_tokens_into_async_str_iter(Self(a, b): Self) -> Self::DomTokensIntoAsyncStrIter {
149+
_ = Self::ASSERT_KNOWN_NOT_DUP;
150+
async_str_iter::chain::Chain::new(
151+
A::dom_tokens_into_async_str_iter(a),
152+
B::dom_tokens_prefix_space_into_async_str_iter(b),
153+
)
154+
}
155+
}
156+
157+
impl<A: ChainableDomTokens, B: ChainableDomTokens> SsrChainableDomTokens for Chain<A, B>
158+
where
159+
Self: HasConstKnownPossibleDomTokens,
160+
{
161+
type DomTokensPrefixSpaceIntoAsyncStrIter = async_str_iter::chain::Chain<
162+
A::DomTokensPrefixSpaceIntoAsyncStrIter,
163+
B::DomTokensPrefixSpaceIntoAsyncStrIter,
164+
>;
165+
166+
fn dom_tokens_prefix_space_into_async_str_iter(
167+
Self(a, b): Self,
168+
) -> Self::DomTokensPrefixSpaceIntoAsyncStrIter {
169+
_ = Self::ASSERT_KNOWN_NOT_DUP;
170+
async_str_iter::chain::Chain::new(
171+
A::dom_tokens_prefix_space_into_async_str_iter(a),
172+
B::dom_tokens_prefix_space_into_async_str_iter(b),
173+
)
174+
}
175+
}
176+
}

0 commit comments

Comments
 (0)