Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
refactor: reconstruct module and reorganize rxjs
Browse files Browse the repository at this point in the history
  • Loading branch information
T2 authored and studioTeaTwo committed Mar 11, 2018
1 parent 5963e39 commit 6f90fdd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/app/app.module.ts
Expand Up @@ -2,19 +2,19 @@ import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { SharedModule } from 'app/shared/shared.module';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CoreModule } from './core/core.module';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
SharedModule.forRoot(),
AppRoutingModule,
CoreModule,
],
declarations: [
AppComponent,
],
providers: [],
bootstrap: [AppComponent]
Expand Down
16 changes: 16 additions & 0 deletions src/app/core/core.module.ts
@@ -0,0 +1,16 @@
import { NgModule, Optional, SkipSelf } from '@angular/core';
import { throwIfAlreadyLoaded } from './module-import-guard';

@NgModule({
imports: [],
declarations: [],
})
export class CoreModule {
constructor(
@Optional()
@SkipSelf()
parentModule: CoreModule,
) {
throwIfAlreadyLoaded(parentModule, 'CoreModule');
}
}
7 changes: 7 additions & 0 deletions src/app/core/module-import-guard.ts
@@ -0,0 +1,7 @@
export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) {
if (parentModule) {
throw new Error(
`${moduleName} has already been loaded. Import Core modules in the AppModule only.`,
);
}
}
14 changes: 0 additions & 14 deletions src/app/shared/rxjs-operators.ts

This file was deleted.

9 changes: 1 addition & 8 deletions src/app/shared/shared.module.ts
@@ -1,7 +1,6 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import 'app/shared/rxjs-operators';

import { MaterialModule } from './material.module';

Expand All @@ -13,16 +12,10 @@ import { MaterialModule } from './material.module';
],
declarations: [],
exports: [
CommonModule,
FormsModule,
MaterialModule,
]
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
providers: [
]
};
}
}

0 comments on commit 6f90fdd

Please sign in to comment.