Skip to content

Commit

Permalink
fix(api): replace deprecated DynamicModule with component module
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Previously deprecated module contained all the pieces of public API in on module
and this was not tree-shakeable. Now it has been removed and replaced by the module that only
contains `DynamicComponent`. All other pieces are available in their own modules.
  • Loading branch information
gund committed Jun 28, 2020
1 parent f6a6ef7 commit 412d517
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 76 deletions.
12 changes: 0 additions & 12 deletions projects/ng-dynamic-component/src/lib/dynamic.component.module.ts

This file was deleted.

68 changes: 6 additions & 62 deletions projects/ng-dynamic-component/src/lib/dynamic.module.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,12 @@
import { ModuleWithProviders, NgModule, Type } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import {
ComponentOutletInjectorModule,
DynamicComponentInjector,
DynamicComponentInjectorToken,
} from './component-injector';
import { DynamicAttributesModule } from './dynamic-attributes';
import { DynamicDirectivesModule } from './dynamic-directives';
import { DynamicIoModule } from './dynamic-io';
import { DynamicComponent } from './dynamic.component';
import { DynamicComponentModule } from './dynamic.component.module';

/**
* @deprecated Since v6.0.0 - use more specific module instead:
* - {@link DynamicIoModule}
* - {@link DynamicComponentModule}
* - {@link DynamicAttributesModule}
* - {@link DynamicDirectivesModule}
* - {@link ComponentOutletInjectorModule}
*/
@NgModule({
exports: [
ComponentOutletInjectorModule,
DynamicIoModule,
DynamicComponentModule,
DynamicAttributesModule,
DynamicDirectivesModule,
],
imports: [CommonModule, DynamicIoModule],
exports: [DynamicComponent, DynamicIoModule],
declarations: [DynamicComponent],
})
export class DynamicModule {
/**
* @deprecated Since v6.0.0 - forRoot is not required anymore.
* Provide {@link DynamicComponentInjectorToken} on the component level instead of global!
*
* **Example:**
* ```ts
* @Component({
* selector: '...',
* providers: [{provide: DynamicComponentInjectorToken, useExisting: MyInjectorComponent}]
* })
* class MyInjectorComponent implements DynamicComponentInjector {...}
* ```
*/
static forRoot(
componentInjector: Type<DynamicComponentInjector> = DynamicComponent,
): ModuleWithProviders<DynamicModule> {
return {
ngModule: DynamicModule,
providers: [
{
provide: DynamicComponentInjectorToken,
useExisting: componentInjector,
},
],
};
}

/**
* @deprecated Since v6.0.0 - Passing a list of components is no longer required. Use `DynamicModule.forRoot()` instead.
*/
static withComponents(
components: Type<any>[],
componentInjector?: Type<DynamicComponentInjector>,
): ModuleWithProviders<DynamicModule> {
return DynamicModule.forRoot(componentInjector);
}
}
export class DynamicModule {}
3 changes: 1 addition & 2 deletions projects/ng-dynamic-component/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

export * from './lib/io/types';
export * from './lib/io/event-argument';
export * from './lib/dynamic.module';
export * from './lib/component-injector';
export * from './lib/dynamic.module';
export * from './lib/dynamic.component';
export * from './lib/dynamic.component.module';
export * from './lib/dynamic-io';
export * from './lib/dynamic-attributes';
export * from './lib/dynamic-directives';

0 comments on commit 412d517

Please sign in to comment.