All files / models asyncComponentTracker.ts

57.14% Statements 8/14
16.67% Branches 1/6
33.33% Functions 1/3
57.14% Lines 8/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27      1x 1x   1x 1x 1x 1x       1x             1x            
import { UpdateAsyncState } from '../actions/asyncState';
import { IAsyncComponent } from './component.types';
 
const components: WeakMap<IAsyncComponent, boolean> = new WeakMap<IAsyncComponent, boolean>();
const keyMap = new Map<Symbol, IAsyncComponent>();
 
export function mountComponent(component: IAsyncComponent) {
  Eif (!components.has(component)) {
    components.set(component, true);
    keyMap.set(component.key, component);
  }
}
 
export function unmountComponent(component: IAsyncComponent) {
  if (components.has(component)) {
    components.delete(component);
    keyMap.delete(component.key);
  }
}
 
export function updateState(action: UpdateAsyncState) {
  const component = keyMap.get(action.key);
  if (component) {
    component.updateAsyncState(action.asyncState);
  }
}