Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function viewBinding(view: any, displayContext: string = DEFAULT_VIEW_KEY) {
Guard.isDefined(view, 'view must be defined');
Guard.isString(displayContext, 'displayContext must be a string');
return function (target) {
let viewMetadata = getMetadata(target);
if (viewMetadata.hasRegisteredViewContext(displayContext)) {
throw new Error(`Context ${displayContext} already registered for view`);
}
viewMetadata.viewRegistrations[displayContext] = new ViewMetadataRegistration(view, displayContext);
};
}
public saveModuleState(moduleKey:string, layoutMode:string, state:T): void {
Guard.isString(moduleKey, 'appKey must be a string');
Guard.isString(layoutMode, 'layoutMode must be a string');
Guard.isDefined(state, 'state must be a defined');
let stateJson = JSON.stringify(state);
let stateKey = this._getStateKey(moduleKey, layoutMode);
_log.debug(`saving layout state for key ${stateKey}. State:${stateJson}`, state);
localStorage.setItem(stateKey, stateJson);
}
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 getModuleState(moduleKey:string, layoutMode:string): T {
Guard.isString(moduleKey, 'moduleKey must be a string');
Guard.isDefined(layoutMode, 'layoutMode must be a defined');
let stateKey = this._getStateKey(moduleKey, layoutMode);
let state = localStorage.getItem(stateKey);
return state ? JSON.parse(state) : null;
}
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);
}
}
constructor(protected _modelId:string, protected _router:Router) {
super();
Guard.isString(_modelId, 'modelId required and must be a string');
Guard.isDefined(_router, 'router required');
this._log = Logger.create(`ModelBase-${_modelId}`);
}
public clearModuleState(moduleKey:string, layoutMode:string): void {
Guard.isString(moduleKey, 'moduleKey must be a string');
Guard.isDefined(layoutMode, 'layoutMode must be a defined');
let stateKey = this._getStateKey(moduleKey, layoutMode);
localStorage.removeItem(stateKey);
}
export function componentFactory(componentKey: string, shortName: string, customMetadata?: any) {
Guard.isDefined(componentKey, 'componentKey must be defined');
return (target) => {
target.__componentMetadata = new ComponentFactoryMetadata(componentKey, shortName, customMetadata);
};
}
Rx.Observable.prototype.subscribeWithRouter = function (
router: Router,
modelId: string,
onNext?: (value: T, model: TModel) => void,
onError?: (exception: any, model: TModel) => void,
onCompleted?: (model: TModel) => void): Rx.Disposable {
Guard.isDefined(router, 'router should be defined');
Guard.isString(modelId, 'modelId should be defined and a string');
let source = this;
return source.materialize().subscribe(i => {
switch (i.kind) {
case 'N':
if (onNext !== null && onNext !== undefined) {
router.runAction(modelId, model => onNext(i.value, model));
}
break;
case 'E':
if (onError === null || onError === undefined) {
throw i.error;
} else {
router.runAction(modelId, model => onError(i.error, model));
}