Skip to content

Commit

Permalink
feat: migrate to standalone component
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuppx committed Dec 9, 2024
1 parent bdc6d9e commit 64463d3
Show file tree
Hide file tree
Showing 29 changed files with 121 additions and 217 deletions.
3 changes: 3 additions & 0 deletions apps/angular/31-module-to-standalone/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Component } from '@angular/core';
import { RouterLink, RouterOutlet } from '@angular/router';

@Component({
selector: 'app-root',
standalone: true,
imports: [RouterLink, RouterOutlet],
template: `
<div class="flex gap-2">
<button
Expand Down
11 changes: 0 additions & 11 deletions apps/angular/31-module-to-standalone/src/app/app.module.ts

This file was deleted.

13 changes: 8 additions & 5 deletions apps/angular/31-module-to-standalone/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import appRoutes from '@angular-challenges/module-to-standalone/shell';
import { importProvidersFrom } from '@angular/core';
import { bootstrapApplication, BrowserModule } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import { AppComponent } from './app/app.component';

platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
bootstrapApplication(AppComponent, {
providers: [importProvidersFrom(BrowserModule), provideRouter(appRoutes)],
}).catch((err) => console.error(err));
2 changes: 1 addition & 1 deletion libs/module-to-standalone/admin/feature/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/admin-feature.module';
export { default } from './lib/admin-feature.routes';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Route } from '@angular/router';

export const ADMIN_FEATURE_ROUTES: Route[] = [
{
path: '',
loadComponent: () =>
import('./dashboard/dashboard.component').then(
(c) => c.DashboardComponent,
),
},
{
path: 'create-user',
loadComponent: () =>
import('./create-user/create-user.component').then(
(c) => c.CreateUserComponent,
),
},
];

export default ADMIN_FEATURE_ROUTES;
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';

@Component({
selector: 'lib-create-user',
standalone: true,
imports: [RouterLink],
template: `
Create User Form
Expand All @@ -14,11 +16,3 @@ import { RouterModule } from '@angular/router';
`,
})
export class CreateUserComponent {}

@NgModule({
imports: [
RouterModule.forChild([{ path: '', component: CreateUserComponent }]),
],
declarations: [CreateUserComponent],
})
export class CreateUserModule {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';

@Component({
selector: 'lib-dashboard',
standalone: true,
imports: [RouterLink],
template: `
Dashboard
Expand All @@ -14,11 +16,3 @@ import { RouterModule } from '@angular/router';
`,
})
export class DashboardComponent {}

@NgModule({
imports: [
RouterModule.forChild([{ path: '', component: DashboardComponent }]),
],
declarations: [DashboardComponent],
})
export class DashboardModule {}
2 changes: 1 addition & 1 deletion libs/module-to-standalone/forbidden/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/forbidden.module';
export { default } from './lib/forbidden.component';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Component } from '@angular/core';

@Component({
selector: 'lib-home',
standalone: true,
template: `
Forbidden component
`,
})
export class ForbiddenComponent {}
export default class ForbiddenComponent {}
13 changes: 0 additions & 13 deletions libs/module-to-standalone/forbidden/src/lib/forbidden.module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/module-to-standalone/home/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/home.module';
export { default } from './lib/home.component';
5 changes: 4 additions & 1 deletion libs/module-to-standalone/home/src/lib/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { TOKEN } from '@angular-challenges/module-to-standalone/core/providers';
import { AuthorizationService } from '@angular-challenges/module-to-standalone/core/service';
import { AsyncPipe } from '@angular/common';
import { Component, Inject } from '@angular/core';

@Component({
selector: 'lib-home',
standalone: true,
imports: [AsyncPipe],
template: `
Home component
Expand All @@ -21,7 +24,7 @@ import { Component, Inject } from '@angular/core';
<section>LoadedToken {{ token }}</section>
`,
})
export class HomeComponent {
export default class HomeComponent {
constructor(
public authorizeService: AuthorizationService,
@Inject(TOKEN) public token: string,
Expand Down
13 changes: 0 additions & 13 deletions libs/module-to-standalone/home/src/lib/home.module.ts

This file was deleted.

4 changes: 3 additions & 1 deletion libs/module-to-standalone/shell/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './lib/main-shell.module';
import { appRoutes } from './lib/main-shell.routes';

export default appRoutes;
11 changes: 0 additions & 11 deletions libs/module-to-standalone/shell/src/lib/main-shell.module.ts

This file was deleted.

58 changes: 29 additions & 29 deletions libs/module-to-standalone/shell/src/lib/main-shell.routes.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import { IsAuthorizedGuard } from '@angular-challenges/module-to-standalone/admin/shared';
import { provideToken } from '@angular-challenges/module-to-standalone/core/providers';
import { Route } from '@angular/router';

export const appRoutes: Route[] = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{
path: 'home',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/home').then(
(m) => m.ModuleToStandaloneHomeModule,
),
},
{
path: 'admin',
canActivate: [IsAuthorizedGuard],
loadChildren: () =>
import('@angular-challenges/module-to-standalone/admin/feature').then(
(m) => m.AdminFeatureModule,
),
},
{
path: 'user',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/user/shell').then(
(m) => m.UserShellModule,
),
},

{
path: 'forbidden',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/forbidden').then(
(m) => m.ForbiddenModule,
),
path: '',
providers: [provideToken('main-shell-token')],
children: [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{
path: 'home',
loadComponent: () =>
import('@angular-challenges/module-to-standalone/home'),
},
{
path: 'admin',
canActivate: [IsAuthorizedGuard],
loadChildren: () =>
import('@angular-challenges/module-to-standalone/admin/feature'),
},
{
path: 'user',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/user/shell').then(
(r) => r.default,
),
},
{
path: 'forbidden',
loadComponent: () =>
import('@angular-challenges/module-to-standalone/forbidden'),
},
],
},
];
2 changes: 1 addition & 1 deletion libs/module-to-standalone/user/contact/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/contact-feature.module';
export { default } from './lib/contact.routes';

This file was deleted.

20 changes: 20 additions & 0 deletions libs/module-to-standalone/user/contact/src/lib/contact.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Route } from '@angular/router';

export const CONTACT_ROUTES: Route[] = [
{
path: '',
loadComponent: () =>
import('./dashboard/dashboard.component').then(
(c) => c.ContactDashboardComponent,
),
},
{
path: 'create-contact',
loadComponent: () =>
import('./create-contact/create-contact.component').then(
(c) => c.CreateContactComponent,
),
},
];

export default CONTACT_ROUTES;
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';

@Component({
selector: 'lib-create-contact',
standalone: true,
imports: [RouterLink],
template: `
Create Contact Form
Expand All @@ -14,11 +16,3 @@ import { RouterModule } from '@angular/router';
`,
})
export class CreateContactComponent {}

@NgModule({
imports: [
RouterModule.forChild([{ path: '', component: CreateContactComponent }]),
],
declarations: [CreateContactComponent],
})
export class CreateContactModule {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';

@Component({
selector: 'lib-contact-dashboard',
standalone: true,
imports: [RouterLink],
template: `
Contact Dashboard
Expand All @@ -14,11 +16,3 @@ import { RouterModule } from '@angular/router';
`,
})
export class ContactDashboardComponent {}

@NgModule({
imports: [
RouterModule.forChild([{ path: '', component: ContactDashboardComponent }]),
],
declarations: [ContactDashboardComponent],
})
export class ContactDashboardModule {}
2 changes: 1 addition & 1 deletion libs/module-to-standalone/user/home/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/home.module';
export { default } from './lib/home.component';
Loading

0 comments on commit 64463d3

Please sign in to comment.