Skip to content

Instantly share code, notes, and snippets.

@ovrmrw
Created January 6, 2018 15:09
Show Gist options
  • Save ovrmrw/791f03d1a9ec2047a35086b98b0f6705 to your computer and use it in GitHub Desktop.
Save ovrmrw/791f03d1a9ec2047a35086b98b0f6705 to your computer and use it in GitHub Desktop.
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