Browse Source
Merge pull request #8212 from abpframework/feat/get-features
Added getFeatures method to ConfigStateService
pull/8218/head
Levent Arman Özak
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
25 additions and
0 deletions
-
npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
-
npm/ng-packs/packages/core/src/lib/utils/factory-utils.ts
|
|
|
@ -72,6 +72,21 @@ export class ConfigStateService { |
|
|
|
return this.store.sliceState(state => state.features?.values?.[key]); |
|
|
|
} |
|
|
|
|
|
|
|
getFeatures(keys: string[]) { |
|
|
|
const { features } = this.store.state; |
|
|
|
if (!features) return; |
|
|
|
|
|
|
|
return keys.reduce((acc, key) => ({ ...acc, [key]: features.values[key] }), {}); |
|
|
|
} |
|
|
|
|
|
|
|
getFeatures$(keys: string[]) { |
|
|
|
return this.store.sliceState(({ features }) => { |
|
|
|
if (!features?.values) return; |
|
|
|
|
|
|
|
return keys.reduce((acc, key) => ({ ...acc, [key]: features.values[key] }), {}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
getSetting(key: string) { |
|
|
|
return this.store.state.setting?.values?.[key]; |
|
|
|
} |
|
|
|
|
|
|
|
@ -7,6 +7,8 @@ import { |
|
|
|
StaticProvider, |
|
|
|
Type, |
|
|
|
} from '@angular/core'; |
|
|
|
import { filter, map } from 'rxjs/operators'; |
|
|
|
import { ConfigStateService } from '../services/config-state.service'; |
|
|
|
|
|
|
|
export class LazyModuleFactory<T> extends NgModuleFactory<T> { |
|
|
|
get moduleType(): Type<T> { |
|
|
|
@ -29,3 +31,11 @@ export class LazyModuleFactory<T> extends NgModuleFactory<T> { |
|
|
|
return factory.create(injector); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export function featuresFactory( |
|
|
|
configState: ConfigStateService, |
|
|
|
featureKeys: string[], |
|
|
|
mapFn: (features) => any = features => features, |
|
|
|
) { |
|
|
|
return configState.getFeatures$(featureKeys).pipe(filter(Boolean), map(mapFn)); |
|
|
|
} |
|
|
|
|