File

src/LockerConfig.ts

Index

Properties

Constructor

constructor(config: ILockerConfig)
Parameters :
Name Type Optional Description
config ILockerConfig

Properties

Public driverFallback
driverFallback: DRIVERS | []
Type : DRIVERS | []
Public driverNamespace
driverNamespace: string
Type : string
Public namespaceSeparator
namespaceSeparator: string
Type : string
import {Inject, Injectable, InjectionToken} from '@angular/core'

import {ILockerConfig} from './metadata'
import {DRIVERS} from './DriverTypes'
import {isNil} from './helpers'

export const LOCKER_USER_CONFIG = new InjectionToken<string>('LOCKER_USER_CONFIG')

const DEFAULT_SEPERATOR = ':'
const DEFAULT_NAMESPACE = ''
const DEFAULT_FALLBACK = DRIVERS.SESSION

export const USER_CONFIG_PROVIDER = {
  provide: LOCKER_USER_CONFIG,
  useValue: {
    namespaceSeparator: DEFAULT_SEPERATOR,
    driverFallback: DEFAULT_FALLBACK,
    driverNamespace: DEFAULT_NAMESPACE
  }
}

const configNotNil = (config: ILockerConfig, prop: keyof ILockerConfig): boolean => !config || isNil(config[prop])

@Injectable()
export class LockerConfig {
  public driverNamespace: string
  public driverFallback: DRIVERS | DRIVERS[]
  public namespaceSeparator: string

  constructor(@Inject(LOCKER_USER_CONFIG) config: ILockerConfig) {
    this.driverNamespace = configNotNil(config, 'driverNamespace') ? DEFAULT_NAMESPACE : config.driverNamespace
    this.driverFallback = configNotNil(config, 'driverFallback') ? DEFAULT_FALLBACK : config.driverFallback
    this.namespaceSeparator = configNotNil(config, 'namespaceSeparator') ? DEFAULT_SEPERATOR : config.namespaceSeparator
  }
}

results matching ""

    No results matching ""