Browse Source

feat(core): add ngxsStoragePluginOptions property to CoreModule forRoot options

resolves #4839
pull/5060/head
mehmet-erim 6 years ago
parent
commit
c3770076b0
  1. 20
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 2
      npm/ng-packs/packages/core/src/lib/models/common.ts
  3. 9
      npm/ng-packs/packages/core/src/lib/tokens/options.token.ts

20
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -4,7 +4,11 @@ import { APP_INITIALIZER, Injector, ModuleWithProviders, NgModule } from '@angul
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { NgxsRouterPluginModule } from '@ngxs/router-plugin';
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
import {
NgxsStoragePluginModule,
NGXS_STORAGE_PLUGIN_OPTIONS,
StorageOption,
} from '@ngxs/storage-plugin';
import { NgxsModule, NGXS_PLUGINS } from '@ngxs/store';
import { OAuthModule, OAuthStorage } from 'angular-oauth2-oidc';
import { AbstractNgModelComponent } from './abstracts/ng-model.component';
@ -118,7 +122,7 @@ export class BaseCoreModule {}
LocalizationModule,
NgxsModule.forFeature([ReplaceableComponentsState, ProfileState, SessionState, ConfigState]),
NgxsRouterPluginModule.forRoot(),
NgxsStoragePluginModule.forRoot({ key: ['SessionState'] }),
NgxsStoragePluginModule.forRoot(),
OAuthModule.forRoot(),
],
})
@ -216,6 +220,18 @@ export class CoreModule {
useFactory: noop,
},
{ provide: OAuthStorage, useFactory: storageFactory },
{
provide: NGXS_STORAGE_PLUGIN_OPTIONS,
useValue: {
storage: StorageOption.LocalStorage,
serialize: JSON.stringify,
deserialize: JSON.parse,
beforeSerialize: obj => obj,
afterDeserialize: obj => obj,
...options.ngxsStoragePluginOptions,
key: [...(options.ngxsStoragePluginOptions?.key || []), 'SessionState'],
},
},
],
};
}

2
npm/ng-packs/packages/core/src/lib/models/common.ts

@ -3,6 +3,7 @@ import { Router } from '@angular/router';
import { Subject } from 'rxjs';
import { eLayoutType } from '../enums/common';
import { Config } from './config';
import { NgxsStoragePluginOptions } from '@ngxs/storage-plugin';
export namespace ABP {
export interface Root {
@ -10,6 +11,7 @@ export namespace ABP {
skipGetAppConfiguration?: boolean;
sendNullsAsQueryParam?: boolean;
cultureNameLocaleFileMap?: Dictionary<string>;
ngxsStoragePluginOptions?: NgxsStoragePluginOptions & { key?: string[] };
}
export interface Test {

9
npm/ng-packs/packages/core/src/lib/tokens/options.token.ts

@ -1,15 +1,12 @@
import { InjectionToken } from '@angular/core';
import { ABP } from '../models/common';
import differentLocales from '../constants/different-locales';
import { ABP } from '../models/common';
export const CORE_OPTIONS = new InjectionToken<ABP.Root>('CORE_OPTIONS');
export function coreOptionsFactory({
cultureNameLocaleFileMap: localeNameMap = {},
...options
}: ABP.Root) {
export function coreOptionsFactory({ cultureNameLocaleFileMap = {}, ...options }: ABP.Root) {
return {
...options,
cultureNameLocaleFileMap: { ...differentLocales, ...localeNameMap },
cultureNameLocaleFileMap: { ...differentLocales, ...cultureNameLocaleFileMap },
} as ABP.Root;
}

Loading…
Cancel
Save