import { GlobalState, GlobalStateProvider, KeyDefinition, UserState, UserStateProvider, } from "../src/platform/state"; import { FakeGlobalState, FakeUserState } from "./fake-state"; export class FakeGlobalStateProvider implements GlobalStateProvider { states: Map, GlobalState> = new Map(); get(keyDefinition: KeyDefinition): GlobalState { let result = this.states.get(keyDefinition) as GlobalState; if (result == null) { result = new FakeGlobalState(); this.states.set(keyDefinition, result); } return result; } getFake(keyDefinition: KeyDefinition): FakeGlobalState { const key = Array.from(this.states.keys()).find( (k) => k.stateDefinition === keyDefinition.stateDefinition && k.key === keyDefinition.key, ); return this.get(key) as FakeGlobalState; } } export class FakeUserStateProvider implements UserStateProvider { states: Map, UserState> = new Map(); get(keyDefinition: KeyDefinition): UserState { let result = this.states.get(keyDefinition) as UserState; if (result == null) { result = new FakeUserState(); this.states.set(keyDefinition, result); } return result; } getFake(keyDefinition: KeyDefinition): FakeUserState { const key = Array.from(this.states.keys()).find( (k) => k.stateDefinition === keyDefinition.stateDefinition && k.key === keyDefinition.key, ); return this.get(key) as FakeUserState; } }