chore: rename ctx to cx
This commit is contained in:
1 parent
23c14078bb
commit
81382e7044
99 files changed
+789
-664
No files matched your search
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
fn main() {
|
||||
// let mut s = Context { props: &() };
|
||||
// let g = Component(&mut s);
|
||||
@@ -15,9 +13,9 @@ fn main() {
|
||||
// Remvoe,
|
||||
// }
|
||||
|
||||
// static Component: FC<()> = |ctx| {
|
||||
// static Component: FC<()> = |cx| {
|
||||
// let (tasks, dispatch) = use_reducer(
|
||||
// ctx,
|
||||
// cx,
|
||||
// || CompState { tasks: Vec::new() },
|
||||
// |state, action: Actions| match action {
|
||||
// Actions::Add => state,
|
||||
@@ -48,7 +46,7 @@ fn main() {
|
||||
// };
|
||||
|
||||
// fn use_reducer<Props, State, Action>(
|
||||
// ctx: &mut Context<Props>,
|
||||
// cx: &mut Context<Props>,
|
||||
// init: fn() -> State,
|
||||
// reducer: fn(State, Action) -> State,
|
||||
// ) -> (State, impl Fn(Action)) {
|
||||
|
||||
@@ -20,7 +20,7 @@ This is moderately efficient because the fields of the map are moved, but the da
|
||||
However, if you used similar approach with Dioxus:
|
||||
|
||||
```rust
|
||||
let (map, set_map) = use_state(&ctx, || HashMap::new());
|
||||
let (map, set_map) = use_state(&cx, || HashMap::new());
|
||||
set_map({
|
||||
let mut newmap = map.clone();
|
||||
newmap.set(key, value);
|
||||
@@ -40,11 +40,11 @@ uses the same memoization on top of the use_context API.
|
||||
|
||||
Here's a fully-functional todo app using the use_map API:
|
||||
```rust
|
||||
static TodoList: FC<()> = |ctx| {
|
||||
let todos = use_map(ctx, || HashMap::new());
|
||||
static TodoList: FC<()> = |cx| {
|
||||
let todos = use_map(cx, || HashMap::new());
|
||||
let input = use_ref(|| None);
|
||||
|
||||
ctx.render(rsx!{
|
||||
cx.render(rsx!{
|
||||
div {
|
||||
button {
|
||||
"Add todo"
|
||||
@@ -84,10 +84,10 @@ fn use_map() {}
|
||||
// Elements are received as Rc<T> in case the underlying collection is shuffled around
|
||||
// Setters/getters can be generated
|
||||
fn use_collection<'a, T: Collection>(
|
||||
ctx: &impl Scoped<'a>,
|
||||
cx: &impl Scoped<'a>,
|
||||
f: impl Fn() -> T,
|
||||
) -> CollectionHandle<'a, T> {
|
||||
ctx.use_hook(
|
||||
cx.use_hook(
|
||||
|| {},
|
||||
|h| {
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user