Feat: massive changes to definition of components
This change switches back to the original `ctx<props>` syntax for commponents. This lets lifetime elision to remove the need to match exactly which lifetime (props or ctx) gets carried to the output. As such, `Props` is currently required to be static. It *is* possible to loosen this restriction, and will be done in the future, though only through adding metadata about the props through the Props derive macro. Implementing the IS_STATIC trait is unsafe, so the derive macro will do it through some heuristics. For now, this unlocks sharing vnodes from parents to children, enabling pass-thru components, fragments, portals, etc.
This commit is contained in:
1 parent
c1fd848f89
commit
508c560320
82 files changed
+692
-558
No files matched your search
+11
-11
@@ -48,8 +48,8 @@ mod use_state_def {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T>(
|
||||
ctx: &'c Context<'a>,
|
||||
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T, P: 'static>(
|
||||
ctx: &'c Context<'a, P>,
|
||||
initial_state_fn: F,
|
||||
) -> (&'a T, &'a Rc<dyn Fn(T)>) {
|
||||
ctx.use_hook(
|
||||
@@ -169,8 +169,8 @@ mod new_use_state_def {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn use_state_new<'a, 'c, T: 'static, F: FnOnce() -> T>(
|
||||
ctx: &'c Context<'a>,
|
||||
pub fn use_state_new<'a, 'c, T: 'static, F: FnOnce() -> T, P: 'static>(
|
||||
ctx: &'c Context<'a, P>,
|
||||
initial_state_fn: F,
|
||||
) -> &'a UseState<T> {
|
||||
ctx.use_hook(
|
||||
@@ -246,8 +246,8 @@ mod use_ref_def {
|
||||
/// To change it, use modify.
|
||||
/// Modifications to this value do not cause updates to the component
|
||||
/// Attach to inner context reference, so context can be consumed
|
||||
pub fn use_ref<'a, T: 'static>(
|
||||
ctx: Context<'a>,
|
||||
pub fn use_ref<'a, T: 'static, P>(
|
||||
ctx: Context<'a, P>,
|
||||
initial_state_fn: impl FnOnce() -> T + 'static,
|
||||
) -> &'a RefCell<T> {
|
||||
ctx.use_hook(|| RefCell::new(initial_state_fn()), |state| &*state, |_| {})
|
||||
@@ -270,11 +270,11 @@ mod use_reducer_def {
|
||||
///
|
||||
/// This is behaves almost exactly the same way as React's "use_state".
|
||||
///
|
||||
pub fn use_reducer<'a, 'c, State: 'static, Action: 'static>(
|
||||
ctx: &'c Context<'a>,
|
||||
pub fn use_reducer<'a, 'c, State: 'static, Action: 'static, P: 'static>(
|
||||
ctx: &'c Context<'a, P>,
|
||||
initial_state_fn: impl FnOnce() -> State,
|
||||
_reducer: impl Fn(&mut State, Action),
|
||||
) -> (&'a State, &'a impl Fn(Action)) {
|
||||
) -> (&'a State, &'a Box<dyn Fn(Action)>) {
|
||||
ctx.use_hook(
|
||||
move || UseReducer {
|
||||
new_val: Rc::new(RefCell::new(None)),
|
||||
@@ -320,7 +320,7 @@ mod use_reducer_def {
|
||||
}
|
||||
|
||||
// #[allow(unused)]
|
||||
// static Example: FC<()> = |ctx, props| {
|
||||
// static Example: FC<()> = |ctx| {
|
||||
// let (count, reduce) = use_reducer(
|
||||
// &ctx,
|
||||
// || 0,
|
||||
@@ -347,7 +347,7 @@ mod use_reducer_def {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn use_is_initialized(ctx: Context) -> bool {
|
||||
pub fn use_is_initialized<P>(ctx: Context<P>) -> bool {
|
||||
let val = use_ref(ctx, || false);
|
||||
match *val.borrow() {
|
||||
true => true,
|
||||
|
||||
Reference in new issue
Block a user