-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructure.module.ts
77 lines (74 loc) · 2.53 KB
/
structure.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Inject, ModuleWithProviders, NgModule, Optional, Type } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FlexModule } from '@angular/flex-layout';
import { ReactiveFormsModule } from '@angular/forms';
import {
ModalModule,
DayModule,
PhoneModule,
TextInputModalModule,
DistanceModule,
ButtonModule,
SvgIconModule
} from '@gouvfr-anct/mediation-numerique/shared';
import { ModalFilterComponent } from '../components/modal-filter/modal-filter.component';
import { StructureListSearchComponent } from '../components/search/structure-list-search.component';
import { CardComponent } from '../components/card/card.component';
import { StructureDetailsComponent } from '../components/structure-details/structure-details.component';
import { LogoCardComponent } from '../components/logo-card/logo-card.component';
import { StructureListComponent } from '../components/structure-list/structure-list.component';
import { SEARCH_TOKEN, SearchRepository } from '../repositories/search.repository';
import { STRUCTURE_TOKEN, StructureRepository } from '../repositories/structure.repository';
@NgModule({
declarations: [
ModalFilterComponent,
StructureListSearchComponent,
CardComponent,
StructureDetailsComponent,
LogoCardComponent,
StructureListComponent
],
exports: [StructureListSearchComponent, StructureListComponent, StructureDetailsComponent, CardComponent],
imports: [
CommonModule,
FlexModule,
ReactiveFormsModule,
SvgIconModule,
ButtonModule,
ModalModule,
DayModule,
PhoneModule,
DistanceModule,
TextInputModalModule
]
})
export class StructureModule {
public static forRoot(
searchRepository: Type<SearchRepository>,
structureRepository: Type<StructureRepository>
): ModuleWithProviders<StructureModule> {
return {
ngModule: StructureModule,
providers: [
{
provide: SEARCH_TOKEN,
useClass: searchRepository
},
{
provide: STRUCTURE_TOKEN,
useClass: structureRepository
}
]
};
}
public constructor(
@Optional() @Inject(SEARCH_TOKEN) private readonly searchRepository: SearchRepository,
@Optional() @Inject(STRUCTURE_TOKEN) private readonly structureRepository: StructureRepository
) {
if ([searchRepository].includes(null)) {
throw new Error(
'Cannot import `StructureListModule` without calling `forRoot` with valid parameters: you must provide defined `searchRepository` and `structureRepository`.'
);
}
}
}