Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public addToRegion(regionName: string, modelId:string, displayOptions?: DisplayOptions): RegionItem {
// I'm not dispatching this call onto the router as by design this model doesn't really have any true observers.
// It does listen to events, but nothing should render it's state, thus this call is synchronous
Guard.stringIsNotEmpty(regionName, 'region name required');
Guard.stringIsNotEmpty(modelId, 'modelId must be defined');
let regionItem = new RegionItem(modelId, displayOptions);
this._addToRegion(regionName, regionItem);
return regionItem;
}
public addToRegion(regionName: string, modelId:string, displayOptions?: DisplayOptions): RegionItem {
// I'm not dispatching this call onto the router as by design this model doesn't really have any true observers.
// It does listen to events, but nothing should render it's state, thus this call is synchronous
Guard.stringIsNotEmpty(regionName, 'region name required');
Guard.stringIsNotEmpty(modelId, 'modelId must be defined');
let regionItem = new RegionItem(modelId, displayOptions);
this._addToRegion(regionName, regionItem);
return regionItem;
}
public removeFromRegion(regionName: string, regionItem: RegionItem): void {
Guard.stringIsNotEmpty(regionName, 'region name required');
Guard.isDefined(regionItem, 'regionItem must be defined');
_log.debug(`Removing from region ${regionName}. ${regionItem.toString()}.`);
if (!(regionName in this._regions)) {
let message = `Cannot remove from region ${regionName} as the region is not registered. ${regionItem}`;
_log.error(message);
throw new Error(message);
}
this._regions[regionName].onRemoving(regionItem);
}
}
return function (target, name, descriptor) {
Guard.stringIsNotEmpty(eventType, 'eventType passed to an eventTransformFor decorator must not be \'\'');
let metadata: EspMetadata = EspDecoratorUtil.getOrCreateMetaData(target.constructor);
metadata.addEvent(
name,
eventType,
DecoratorTypes.custom,
observationStage,
null
);
return descriptor;
};
}
return function (target, name, descriptor) {
Guard.stringIsNotEmpty(eventType, 'eventType passed to an observeStoreEvent decorator must not be \'\'');
let metadata: EspMetadata = EspDecoratorUtil.getOrCreateMetaData(target.constructor);
metadata.addEvent(
name,
eventType,
DecoratorTypes.custom,
observationStage,
null
);
return descriptor;
};
}
constructor(
private readonly _router: Router,
private _store: TStore,
private readonly _stateHandlerMaps: Map>,
private readonly _stateHandlerObjects: Map,
private readonly _eventStreamFactories: OutputEventStreamFactory[],
private readonly _eventStreamHandlerObjects: any[]
) {
super();
Guard.isDefined(_router, 'router must be defined');
Guard.isObject(_store, 'store must be defined and be an object');
Guard.stringIsNotEmpty(_store.modelId, `Initial store's modelId must not be null or empty`);
this._modelId = _store.modelId;
}
public registerRegion(regionName: string, onAddingViewToRegionCallback: ViewCallBack, onRemovingFromRegionCallback: ViewCallBack) {
Guard.stringIsNotEmpty(regionName, 'region name required');
Guard.isFunction(onAddingViewToRegionCallback, 'onAddingViewToRegionCallback must be a function');
Guard.isFunction(onRemovingFromRegionCallback, 'onRemovingFromRegionCallback must be a function');
_log.debug('registering region {0}', regionName);
if (this._regions[regionName]) {
let message = `Cannot register region ${regionName} as it is already registered`;
_log.error(message);
throw new Error(message);
}
this._regions[regionName] = {
onAdding: onAddingViewToRegionCallback,
onRemoving: onRemovingFromRegionCallback
};
}