feat: apply local router changes
This commit is contained in:
1 parent
3928856a9b
commit
f2979cb12a
28 files changed
+672
-516
No files matched your search
+11
-14
@@ -327,12 +327,12 @@ impl ScopeArena {
|
||||
while let Some(id) = cur_el.take() {
|
||||
if let Some(el) = nodes.get(id.0) {
|
||||
let real_el = unsafe { &**el };
|
||||
log::debug!("looking for listener on {:?}", real_el);
|
||||
log::trace!("looking for listener on {:?}", real_el);
|
||||
|
||||
if let VNode::Element(real_el) = real_el {
|
||||
for listener in real_el.listeners.borrow().iter() {
|
||||
if listener.event == event.name {
|
||||
log::debug!("calling listener {:?}", listener.event);
|
||||
log::trace!("calling listener {:?}", listener.event);
|
||||
if state.canceled.get() {
|
||||
// stop bubbling if canceled
|
||||
break;
|
||||
@@ -489,7 +489,7 @@ pub struct ScopeState {
|
||||
pub(crate) hook_idx: Cell<usize>,
|
||||
|
||||
// shared state -> todo: move this out of scopestate
|
||||
pub(crate) shared_contexts: RefCell<HashMap<TypeId, Rc<dyn Any>>>,
|
||||
pub(crate) shared_contexts: RefCell<HashMap<TypeId, Box<dyn Any>>>,
|
||||
pub(crate) tasks: Rc<TaskQueue>,
|
||||
}
|
||||
|
||||
@@ -676,11 +676,10 @@ impl ScopeState {
|
||||
/// rsx!(cx, div { "hello {state.0}" })
|
||||
/// }
|
||||
/// ```
|
||||
pub fn provide_context<T: 'static>(&self, value: T) -> Rc<T> {
|
||||
let value = Rc::new(value);
|
||||
pub fn provide_context<T: 'static + Clone>(&self, value: T) -> T {
|
||||
self.shared_contexts
|
||||
.borrow_mut()
|
||||
.insert(TypeId::of::<T>(), value.clone())
|
||||
.insert(TypeId::of::<T>(), Box::new(value.clone()))
|
||||
.and_then(|f| f.downcast::<T>().ok());
|
||||
value
|
||||
}
|
||||
@@ -703,14 +702,12 @@ impl ScopeState {
|
||||
/// rsx!(cx, div { "hello {state.0}" })
|
||||
/// }
|
||||
/// ```
|
||||
pub fn provide_root_context<T: 'static>(&self, value: T) -> Rc<T> {
|
||||
let value = Rc::new(value);
|
||||
|
||||
pub fn provide_root_context<T: 'static + Clone>(&self, value: T) -> T {
|
||||
// if we *are* the root component, then we can just provide the context directly
|
||||
if self.scope_id() == ScopeId(0) {
|
||||
self.shared_contexts
|
||||
.borrow_mut()
|
||||
.insert(TypeId::of::<T>(), value.clone())
|
||||
.insert(TypeId::of::<T>(), Box::new(value.clone()))
|
||||
.and_then(|f| f.downcast::<T>().ok());
|
||||
return value;
|
||||
}
|
||||
@@ -724,7 +721,7 @@ impl ScopeState {
|
||||
let exists = parent
|
||||
.shared_contexts
|
||||
.borrow_mut()
|
||||
.insert(TypeId::of::<T>(), value.clone());
|
||||
.insert(TypeId::of::<T>(), Box::new(value.clone()));
|
||||
|
||||
if exists.is_some() {
|
||||
log::warn!("Context already provided to parent scope - replacing it");
|
||||
@@ -739,9 +736,9 @@ impl ScopeState {
|
||||
}
|
||||
|
||||
/// Try to retrieve a SharedState with type T from the any parent Scope.
|
||||
pub fn consume_context<T: 'static>(&self) -> Option<Rc<T>> {
|
||||
pub fn consume_context<T: 'static + Clone>(&self) -> Option<T> {
|
||||
if let Some(shared) = self.shared_contexts.borrow().get(&TypeId::of::<T>()) {
|
||||
Some(shared.clone().downcast::<T>().unwrap())
|
||||
Some((*shared.downcast_ref::<T>().unwrap()).clone())
|
||||
} else {
|
||||
let mut search_parent = self.parent_scope;
|
||||
|
||||
@@ -749,7 +746,7 @@ impl ScopeState {
|
||||
// safety: all parent pointers are valid thanks to the bump arena
|
||||
let parent = unsafe { &*parent_ptr };
|
||||
if let Some(shared) = parent.shared_contexts.borrow().get(&TypeId::of::<T>()) {
|
||||
return Some(shared.clone().downcast::<T>().unwrap());
|
||||
return Some(shared.downcast_ref::<T>().unwrap().clone());
|
||||
}
|
||||
search_parent = parent.parent_scope;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user