Created
January 6, 2018 15:09
-
-
Save ovrmrw/791f03d1a9ec2047a35086b98b0f6705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { WindowWrapper } from './WindowWrapper'; | |
let _namespace: Namespace | undefined; | |
export class Namespace { | |
private readonly key: string; | |
static fromName(key: string): Namespace { | |
if (!_namespace) { | |
_namespace = new Namespace(key); | |
} | |
return _namespace; | |
} | |
static getInstance(): Namespace { | |
if (!_namespace) { | |
throw new Error('Create the instance by fromKeyname method before calling getInstance method'); | |
} | |
return _namespace; | |
} | |
static removeInstance(): void { | |
_namespace = void 0; | |
} | |
private constructor(key: string) { | |
this.key = key; | |
} | |
namespace: () => any = () => { | |
const window = WindowWrapper.getInstance().window; | |
return window[this.key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment