fn _create_effect(mut effect: Box<dyn FnMut()>) {
    let listener: Rc<RefCell<Option<Listener>>> = Rc::new(RefCell::new(None));

    // Callback for when the effect's dependencies are triggered.
    let callback: Rc<RefCell<dyn FnMut()>> = Rc::new(RefCell::new({
        let listener = Rc::downgrade(&listener);
        move || {
            LISTENERS.with(|listeners| {
                // Record initial context size to verify that it is the same after.
                let initial_context_size = listeners.borrow().len();

                // Upgrade running now to make sure running is valid for the whole duration of
                // the effect.
                let listener = listener.upgrade().unwrap_throw();

                // Push new reactive scope.
                listeners.borrow_mut().push(Rc::downgrade(&listener));

                let mut listener_mut = listener.borrow_mut();
                let listener_ref = listener_mut.as_mut().unwrap_throw();

                let old_dependencies = mem::take(&mut listener_ref.dependencies);

                // Get old scope's parent so that new scope does not change scope hierarchy.
                let parent = listener_ref.scope.0.borrow().parent.clone();

                // We want to destroy the old scope before creating the new one, so that cleanup
                // functions will be run before the effect closure is called again.
                let _ = mem::take(&mut listener_ref.scope);

                drop(listener_mut); // Drop the RefMut because Signals will access it inside the effect callback.
                let new_scope = create_child_scope_in(&parent, || {
                    // Run effect closure.
                    effect();
                });
                let mut listener_mut = listener.borrow_mut();
                let listener_ref = listener_mut.as_mut().unwrap_throw();
                listener_ref.scope = new_scope;

                // Unsubscribe from removed dependencies.
                // Removed dependencies are those that are in old dependencies but not in new
                // dependencies.
                for old_dependency in old_dependencies.difference(&listener_ref.dependencies) {
                    old_dependency
                        .signal()
                        .unsubscribe(listener_ref.callback.as_ref());
                }

                // Subscribe to new dependencies.
                // New dependencies are those that are in new dependencies but not in old
                // dependencies.
                for new_dependency in listener_ref.dependencies.difference(&old_dependencies) {
                    new_dependency.signal().subscribe(Callback(Rc::downgrade(
                        // Reference the same closure we are in right now.
                        // When the dependency changes, this closure will be called again.
                        &listener_ref.callback,
                    )));
                }

                // Remove reactive context.
                listeners.borrow_mut().pop();

                debug_assert_eq!(
                    initial_context_size,
                    listeners.borrow().len(),
                    "context size should not change before and after create_effect_initial"
                );
            });
        }
    }));

    *listener.borrow_mut() = Some(Listener {
        callback: Rc::clone(&callback),
        dependencies: AHashSet::new(),
        scope: ReactiveScope::new(), /* This is a placeholder and will be replaced when callback
                                      * is called. */
    });
    debug_assert_eq!(
        Rc::strong_count(&listener),
        1,
        "Running should be owned exclusively by ReactiveScope"
    );

    SCOPES.with(|scope| {
        if scope.borrow().last().is_some() {
            scope
                .borrow_mut()
                .last_mut()
                .unwrap_throw()
                .add_effect_state(listener);
        } else {
            thread_local! {
                static GLOBAL_SCOPE: RefCell<ReactiveScope> = RefCell::new(ReactiveScope::new());
            }
            GLOBAL_SCOPE.with(|global_scope| global_scope.borrow_mut().add_effect_state(listener));
        }
    });

    callback.borrow_mut()();
}
/// Internal implementation: use dynamic dispatch to reduce code bloat.
Internal implementation: use dynamic dispatch to reduce code bloat.
Internal implementation : use dynamic dispatch to reduce code bloat .
fn _create_effect(mut effect: Box<dyn FnMut()>) {
    let listener: Rc<RefCell<Option<Listener>>> = Rc::new(RefCell::new(None));
    // Callback for when the effect's dependencies are triggered.
    let callback: Rc<RefCell<dyn FnMut()>> = Rc::new(RefCell::new({
        let listener = Rc::downgrade(&listener);
        move || {
            LISTENERS.with(|listeners| {
                // Record initial context size to verify that it is the same after.
                let initial_context_size = listeners.borrow().len();
                // Upgrade running now to make sure running is valid for the whole duration of
                // the effect.
                let listener = listener.upgrade().unwrap_throw();
                // Push new reactive scope.
                listeners.borrow_mut().push(Rc::downgrade(&listener));
                let mut listener_mut = listener.borrow_mut();
                let listener_ref = listener_mut.as_mut().unwrap_throw();
                let old_dependencies = mem::take(&mut listener_ref.dependencies);
                // Get old scope's parent so that new scope does not change scope hierarchy.
                let parent = listener_ref.scope.0.borrow().parent.clone();
                // We want to destroy the old scope before creating the new one, so that cleanup
                // functions will be run before the effect closure is called again.
                let _ = mem::take(&mut listener_ref.scope);
                drop(listener_mut); // Drop the RefMut because Signals will access it inside the effect callback.
                let new_scope = create_child_scope_in(&parent, || {
                    // Run effect closure.
                    effect();
                });
                let mut listener_mut = listener.borrow_mut();
                let listener_ref = listener_mut.as_mut().unwrap_throw();
                listener_ref.scope = new_scope;
                // Unsubscribe from removed dependencies.
                // Removed dependencies are those that are in old dependencies but not in new
                // dependencies.
                for old_dependency in old_dependencies.difference(&listener_ref.dependencies) {
                    old_dependency
                        .signal()
                        .unsubscribe(listener_ref.callback.as_ref());
                }
                // Subscribe to new dependencies.
                // New dependencies are those that are in new dependencies but not in old
                // dependencies.
                for new_dependency in listener_ref.dependencies.difference(&old_dependencies) {
                    new_dependency.signal().subscribe(Callback(Rc::downgrade(
                        // Reference the same closure we are in right now.
                        // When the dependency changes, this closure will be called again.
                        &listener_ref.callback,
                    )));
                }
                // Remove reactive context.
                listeners.borrow_mut().pop();
                debug_assert_eq!(
                    initial_context_size,
                    listeners.borrow().len(),
                    "context size should not change before and after create_effect_initial"
                );
            });
        }
    }));
    *listener.borrow_mut() = Some(Listener {
        callback: Rc::clone(&callback),
        dependencies: AHashSet::new(),
        scope: ReactiveScope::new(), /* This is a placeholder and will be replaced when callback
                                      * is called. */
    });
    debug_assert_eq!(
        Rc::strong_count(&listener),
        1,
        "Running should be owned exclusively by ReactiveScope"
    );
    SCOPES.with(|scope| {
        if scope.borrow().last().is_some() {
            scope
                .borrow_mut()
                .last_mut()
                .unwrap_throw()
                .add_effect_state(listener);
        } else {
            thread_local! {
                static GLOBAL_SCOPE: RefCell<ReactiveScope> = RefCell::new(ReactiveScope::new());
            }
            GLOBAL_SCOPE.with(|global_scope| global_scope.borrow_mut().add_effect_state(listener));
        }
    });
    callback.borrow_mut()();
}
fn _create_effect ( mut effect : Box < dyn FnMut ( ) > ) { let listener : Rc < RefCell < Option < Listener > > > = Rc :: new ( RefCell :: new ( None ) ) ; // Callback for when the effect's dependencies are triggered. let callback : Rc < RefCell < dyn FnMut ( ) > > = Rc :: new ( RefCell :: new ( { let listener = Rc :: downgrade ( & listener ) ; move | | { LISTENERS . with ( | listeners | { // Record initial context size to verify that it is the same after. let initial_context_size = listeners . borrow ( ) . len ( ) ; // Upgrade running now to make sure running is valid for the whole duration of // the effect. let listener = listener . upgrade ( ) . unwrap_throw ( ) ; // Push new reactive scope. listeners . borrow_mut ( ) . push ( Rc :: downgrade ( & listener ) ) ; let mut listener_mut = listener . borrow_mut ( ) ; let listener_ref = listener_mut . as_mut ( ) . unwrap_throw ( ) ; let old_dependencies = mem :: take ( & mut listener_ref . dependencies ) ; // Get old scope's parent so that new scope does not change scope hierarchy. let parent = listener_ref . scope . 0 . borrow ( ) . parent . clone ( ) ; // We want to destroy the old scope before creating the new one, so that cleanup // functions will be run before the effect closure is called again. let _ = mem :: take ( & mut listener_ref . scope ) ; drop ( listener_mut ) ; // Drop the RefMut because Signals will access it inside the effect callback. let new_scope = create_child_scope_in ( & parent , | | { // Run effect closure. effect ( ) ; } ) ; let mut listener_mut = listener . borrow_mut ( ) ; let listener_ref = listener_mut . as_mut ( ) . unwrap_throw ( ) ; listener_ref . scope = new_scope ; // Unsubscribe from removed dependencies. // Removed dependencies are those that are in old dependencies but not in new // dependencies. for old_dependency in old_dependencies . difference ( & listener_ref . dependencies ) { old_dependency . signal ( ) . unsubscribe ( listener_ref . callback . as_ref ( ) ) ; } // Subscribe to new dependencies. // New dependencies are those that are in new dependencies but not in old // dependencies. for new_dependency in listener_ref . dependencies . difference ( & old_dependencies ) { new_dependency . signal ( ) . subscribe ( Callback ( Rc :: downgrade ( // Reference the same closure we are in right now. // When the dependency changes, this closure will be called again. & listener_ref . callback , ) ) ) ; } // Remove reactive context. listeners . borrow_mut ( ) . pop ( ) ; debug_assert_eq ! ( initial_context_size listeners borrow ( ) len ( ) " " ) ; } ) ; } } ) ) ; * listener . borrow_mut ( ) = Some ( Listener { callback : Rc :: clone ( & callback ) , dependencies : AHashSet :: new ( ) , scope : ReactiveScope :: new ( ) , /* This is a placeholder and will be replaced when callback
                                      * is called. */ } ) ; debug_assert_eq ! ( Rc strong_count ( listener ) 1 " " ) ; SCOPES . with ( | scope | { if scope . borrow ( ) . last ( ) . is_some ( ) { scope . borrow_mut ( ) . last_mut ( ) . unwrap_throw ( ) . add_effect_state ( listener ) ; } else { thread_local ! { static GLOBAL_SCOPE RefCell ReactiveScope RefCell new ( ReactiveScope new ( ) ) } GLOBAL_SCOPE . with ( | global_scope | global_scope . borrow_mut ( ) . add_effect_state ( listener ) ) ; } } ) ; callback . borrow_mut ( ) ( ) ; }
Internal implementation: use dynamic dispatch to reduce code bloat.
Internal implementation : use dynamic dispatch to reduce code bloat .
effect
Box<dyn FnMut()>