import {Meta} from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional/# Global Effect Scope'/>

# Global Effect Scope

The **EffectScopeGlobal** class provides access to a unified, long-running effect scope (**EffectScope**) in **Vue 3**. This allows for the creation of reactive dependencies (watch, computed) that are not tied to the lifecycle of specific components.

## Features

- **Persistence**: Effects launched via this class live for the entire duration of the application.
- **Isolation**: Allows for grouping global reactive processes in one place to prevent memory leaks.
- **Control**: All dependencies created inside `run()` are automatically associated with the global context.

## Usage Examples

Typically used to set up global listeners or computed properties that must remain available throughout the entire application.

```javascript
import { watch, ref } from 'vue'
import { EffectScopeGlobal } from '@dxtmisha/functional'

const globalState = ref(0)

// 1. Starting a global process
EffectScopeGlobal.run(() => {
  watch(globalState, (val) => {
    console.log('Global state changed:', val)
  })
})

// 2. Creating long-lived computed properties
const persistentValue = EffectScopeGlobal.run(() => {
  return computed(() => globalState.value * 2)
})
```

This approach ensures that even if the component initiating the creation of this `watch` is unmounted, the watcher will continue to function.
