All files / core/lib/Interfaces Context.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 3/3
100% Lines 11/11
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 28 29 30 31 32 33 34 35  2x   20x   2x   8x   2x   8x 7x   8x 3x     5x     2x                          
import { IUser } from './User';
 
export interface IContext {
  tags?: any;
  extra?: any;
  user?: IUser;
}
 
export function getDefaultContext() {
  return {};
}
 
export function set<T extends IContext, K extends keyof T>(
  context: T,
  key: K,
  value: any
) {
  context[key] = value;
}
 
export function mergeIn<T extends IContext, K extends keyof T>(
  context: T,
  key: K,
  value: any
) {
  if (!context[key]) {
    set(context, key, {});
  }
  if (value === undefined) {
    delete context[key];
  } else {
    Object.assign(context[key], value);
  }
}