📄 createGlobalState¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📦 Imports | 2 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/shared/createGlobalState/index.ts
📦 Imports¶
| Name | Source |
|---|---|
AnyFn |
../utils |
effectScope |
vue |
Functions¶
createGlobalState(stateFactory: Fn): CreateGlobalStateReturn<Fn>¶
Keep states in the global scope to be reusable across Vue instances.
Parameters:
stateFactoryany: A factory function to create the state
See: https://vueuse.org/createGlobalState
Tags: @__NO_SIDE_EFFECTS__
Raw JSDoc
Calls:
effectScope (from vue)scope.runstateFactory
Code
export function createGlobalState<Fn extends AnyFn>(
stateFactory: Fn,
): CreateGlobalStateReturn<Fn> {
let initialized = false
let state: any
const scope = effectScope(true)
return ((...args: any[]) => {
if (!initialized) {
state = scope.run(() => stateFactory(...args))!
initialized = true
}
return state
}) as Fn
}
Type Aliases¶
CreateGlobalStateReturn<Fn extends AnyFn = AnyFn>¶
Generated by Syntax Scribe