Skip to content
This repository was archived by the owner on Nov 3, 2024. It is now read-only.

Commit 8ebb878

Browse files
refactor(config): module config registration (#48)
1 parent 1914af2 commit 8ebb878

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
This was added due to a limitation (which previously was handled via hack and is not supported anymore). [See this issue](https://github.com/angular/angular/issues/8277).
1313
- **module:** rename module to `SsvCommandModule` from `CommandModule`
1414

15+
## [1.6.1](https://github.com/sketch7/ngx.ux/compare/1.6.0...1.6.1) (2020-11-07)
16+
17+
### Refactor
18+
19+
- **config:** refactor module config registration
20+
1521
## [1.6.0](https://github.com/sketch7/ngx.ux/compare/1.5.2...1.6.0) (2020-11-04)
1622

1723
### Features

src/module.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1-
import { NgModule, ModuleWithProviders, InjectionToken } from "@angular/core";
1+
import { NgModule, ModuleWithProviders, InjectionToken, Optional } from "@angular/core";
22

33
import { CommandDirective } from "./command.directive";
44
import { CommandRefDirective } from "./command-ref.directive";
55
import { CommandOptions, COMMAND_DEFAULT_CONFIG, COMMAND_CONFIG } from "./config";
66

77
/** @internal */
8-
export const _MODULE_CONFIG = new InjectionToken<CommandOptions>("_command-config");
8+
export const MODULE_CONFIG_DATA = new InjectionToken<CommandOptions>("@ssv/ngx.command/configData");
9+
10+
const components = [
11+
CommandDirective,
12+
CommandRefDirective
13+
];
914

1015
@NgModule({
11-
declarations: [CommandDirective, CommandRefDirective],
12-
providers: [{ provide: COMMAND_CONFIG, useValue: COMMAND_DEFAULT_CONFIG }],
13-
exports: [CommandDirective, CommandRefDirective],
16+
declarations: components,
17+
providers: [
18+
{ provide: COMMAND_CONFIG, useFactory: _moduleConfigFactory, deps: [[MODULE_CONFIG_DATA, new Optional()]] },
19+
],
20+
exports: [...components],
1421
})
1522
export class SsvCommandModule {
1623

1724
static forRoot(config?: Partial<CommandOptions> | (() => Partial<CommandOptions>)): ModuleWithProviders<SsvCommandModule> {
1825
return {
1926
ngModule: SsvCommandModule,
2027
providers: [
21-
{
22-
provide: COMMAND_CONFIG,
23-
useFactory: moduleConfigFactory,
24-
deps: [_MODULE_CONFIG],
25-
},
26-
{ provide: _MODULE_CONFIG, useValue: config },
28+
{ provide: MODULE_CONFIG_DATA, useValue: config },
2729
],
2830
};
2931
}
3032

3133
}
3234

3335
/** @internal */
34-
export function moduleConfigFactory(config: CommandOptions | (() => CommandOptions)): CommandOptions {
36+
export function _moduleConfigFactory(config: CommandOptions | (() => CommandOptions)): CommandOptions {
3537
const cfg = typeof config === "function" ? config() : config;
3638
return cfg
3739
? {

0 commit comments

Comments
 (0)