( initial: (environment: Environment) => State, )
| 18 | * @experimental |
| 19 | */ |
| 20 | export function perEnvironmentState<State>( |
| 21 | initial: (environment: Environment) => State, |
| 22 | ): (context: PluginContext) => State { |
| 23 | const stateMap = new WeakMap<Environment, State>() |
| 24 | return function (context: PluginContext) { |
| 25 | const { environment } = context |
| 26 | if (!stateMap.has(environment)) { |
| 27 | stateMap.set(environment, initial(environment)) |
| 28 | } |
| 29 | return stateMap.get(environment)! |
| 30 | } |
| 31 | } |
no test coverage detected