pagamio-frontend-commons-lib
Version:
Pagamio library for Frontend reusable components like the form engine and table container
38 lines (37 loc) • 1.18 kB
JavaScript
/**
* Singleton store for RBAC configuration
* This allows the RBAC system to be initialized once and used throughout the application
*/
export class RBACConfigStore {
// Use a more generic type for the static instance to avoid type conflicts
static instance;
_options = null;
constructor() { }
/**
* Get the singleton instance of the RBAC config store
*/
static getInstance() {
// Use nullish coalescing assignment for cleaner code
RBACConfigStore.instance ??= new RBACConfigStore();
// Using type assertion here as we know the instance will be compatible
// with the requested generic types
return RBACConfigStore.instance;
}
/**
* Initialize the RBAC configuration
* @param options - RBAC configuration options
*/
initialize(options) {
this._options = options;
}
/**
* Get the RBAC configuration options
* @throws Error if RBAC has not been initialized
*/
get options() {
if (!this._options) {
throw new Error('RBAC has not been initialized. Call initializeRBAC first.');
}
return this._options;
}
}