popScope static method

void popScope(
  1. String scopeName
)

Called when a scope is disposed or becomes inactive

Implementation

static void popScope(String scopeName) {
  final removed = _scopeStack.remove(scopeName);
  _scopeCreationTimes.remove(scopeName);
  _scopeUsesParentScope.remove(scopeName);

  if (removed) {
    ZenLogger.logDebug('๐Ÿ“š Scope stack pop: ${_formatStack()}');

    // Check if we're popping back to a non-parent-scope route
    final currentTopScope = getCurrentScope();
    if (currentTopScope != null) {
      final topScopeUsesParentScope =
          _scopeUsesParentScope[currentTopScope] ?? true;
      if (!topScopeUsesParentScope) {
        ZenLogger.logDebug(
            '๐Ÿงน Popped back to non-parent-scope route: $currentTopScope. Triggering cleanup.');
        // Trigger cleanup when popping back to a route that doesn't use parent scope
        ZenScopeManager.cleanupAllScopesExcept(currentTopScope);
      }
    }
  }
}