-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bring internal module manager APIs from #926
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
projects/ngx-meta/src/core/src/managers/provider/provide-ngx-meta-module-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { | ||
_ProvideNgxMetaManagerOptions, | ||
provideNgxMetaManager, | ||
withManagerDeps, | ||
withManagerGlobal, | ||
withManagerJsonPath, | ||
} from './provide-ngx-meta-manager' | ||
import { | ||
NgxMetaElementNameAttribute, | ||
NgxMetaElementsService, | ||
withContentAttribute, | ||
withNameAttribute, | ||
} from '../../meta-elements' | ||
import { MetadataSetterFactory } from './make-metadata-manager-provider-from-setter-factory' | ||
import { withOptions } from '../../utils' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const _provideNgxMetaModuleManager = < | ||
Type extends object, | ||
Key extends StringKey<Type>, | ||
>( | ||
key: Key, | ||
scope: ReadonlyArray<string>, | ||
options: _ProvideNgxMetaModuleManagerOptions<Type[Key]> = {}, | ||
) => | ||
provideNgxMetaManager( | ||
withManagerJsonPath(...scope, key), | ||
options.f ?? | ||
((metaElementsService: NgxMetaElementsService) => (value) => | ||
metaElementsService.set( | ||
options.n ?? withNameAttribute(key), | ||
withContentAttribute(value as string | null | undefined), | ||
)), | ||
withOptions( | ||
withManagerDeps(options.d ?? [NgxMetaElementsService]), | ||
options.gS ? withManagerGlobal(key) : {}, | ||
options, | ||
), | ||
) | ||
|
||
type StringKey<T = object> = Extract<keyof T, string> | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export type _ProvideNgxMetaModuleManagerOptions<T> = Partial<{ | ||
f: MetadataSetterFactory<T> | ||
n: NgxMetaElementNameAttribute | ||
gS: true | ||
}> & | ||
_ProvideNgxMetaManagerOptions | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const _withModuleManagerSetterFactory = <T>( | ||
setterFactory: _ProvideNgxMetaModuleManagerOptions<T>['f'], | ||
): _ProvideNgxMetaModuleManagerOptions<T> => ({ | ||
f: setterFactory, | ||
}) | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const _withModuleManagerNameAttribute = <T>( | ||
nameAttribute: _ProvideNgxMetaModuleManagerOptions<T>['n'], | ||
): _ProvideNgxMetaModuleManagerOptions<T> => ({ | ||
n: nameAttribute, | ||
}) | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const _withSameNameGlobal = < | ||
T, | ||
>(): _ProvideNgxMetaModuleManagerOptions<T> => ({ | ||
gS: true, | ||
}) |