Skip to content

Commit

Permalink
Additions/52 lazy load component (tomalaforge#963)
Browse files Browse the repository at this point in the history
* feat: create challenge 52 on lazy load component

Initial boilerplate from `nx g @angular-challenges/cli:challenge`

* feat: revert to NgModule

Copy of 31

* feat: initial version of starting point

* feat: add documentation

* feat: pr tweaks

Add author file
Remove thomas from the contributor list
Add a more direct hint

* feat: pr tweaks

Update "Go to the latest Challenge" link
  • Loading branch information
LMFinney authored May 27, 2024
1 parent a07954f commit c8ba057
Show file tree
Hide file tree
Showing 29 changed files with 397 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you would like to propose a challenge, this project is open source, so feel f
## Challenges

Check [all 51 challenges](https://angular-challenges.vercel.app/)
Check [all 52 challenges](https://angular-challenges.vercel.app/)

## Contributors ✨

Expand Down
36 changes: 36 additions & 0 deletions apps/angular/52-lazy-load-component/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}
13 changes: 13 additions & 0 deletions apps/angular/52-lazy-load-component/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# lazy-load-component

> author: thomas-laforge
### Run Application

```bash
npx nx serve angular-lazy-load-component
```

### Documentation and Instruction

Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/angular/52-lazy-load-component/).
22 changes: 22 additions & 0 deletions apps/angular/52-lazy-load-component/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'angular-lazy-load-component',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../../coverage/apps/angular/52-lazy-load-component',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
79 changes: 79 additions & 0 deletions apps/angular/52-lazy-load-component/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "angular-lazy-load-component",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"prefix": "app",
"sourceRoot": "apps/angular/52-lazy-load-component/src",
"tags": [],
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/angular/52-lazy-load-component",
"index": "apps/angular/52-lazy-load-component/src/index.html",
"browser": "apps/angular/52-lazy-load-component/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/angular/52-lazy-load-component/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"apps/angular/52-lazy-load-component/src/favicon.ico",
"apps/angular/52-lazy-load-component/src/assets"
],
"styles": ["apps/angular/52-lazy-load-component/src/styles.scss"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "angular-lazy-load-component:build:production"
},
"development": {
"buildTarget": "angular-lazy-load-component:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "angular-lazy-load-component:build"
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/angular/52-lazy-load-component/jest.config.ts"
}
}
}
}
22 changes: 22 additions & 0 deletions apps/angular/52-lazy-load-component/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, signal } from '@angular/core';

@Component({
selector: 'app-root',
template: `
<div class="h-screen bg-gray-500">
@if (topLoaded()) {
<app-top />
} @else {
<app-placeholder />
<button
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="topLoaded.set(true)">
Load Top
</button>
}
</div>
`,
})
export class AppComponent {
topLoaded = signal(false);
}
12 changes: 12 additions & 0 deletions apps/angular/52-lazy-load-component/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { PlaceholderComponent } from './placeholder.component';
import { TopComponent } from './top.component';

@NgModule({
declarations: [AppComponent, PlaceholderComponent, TopComponent],
imports: [BrowserModule],
bootstrap: [AppComponent],
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-placeholder',
template: `
I'm a placeholder component.
`,
styles: `
:host {
display: grid;
padding: 20px;
background-color: #f0f0f0;
height: 50%;
}
`,
})
export class PlaceholderComponent {}
17 changes: 17 additions & 0 deletions apps/angular/52-lazy-load-component/src/app/top.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-top',
template: `
I am a very heavy, expensive component that should be lazy loaded.
`,
styles: `
:host {
display: grid;
padding: 20px;
background-color: #f0f0f0;
height: 50%;
}
`,
})
export class TopComponent {}
Empty file.
Binary file not shown.
13 changes: 13 additions & 0 deletions apps/angular/52-lazy-load-component/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>angular-lazy-load-component</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>
6 changes: 6 additions & 0 deletions apps/angular/52-lazy-load-component/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';

platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
5 changes: 5 additions & 0 deletions apps/angular/52-lazy-load-component/src/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

/* You can add global styles to this file, and also import other style files */
2 changes: 2 additions & 0 deletions apps/angular/52-lazy-load-component/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@testing-library/jest-dom';
import 'jest-preset-angular/setup-jest';
14 changes: 14 additions & 0 deletions apps/angular/52-lazy-load-component/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind');
const { join } = require('path');

/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'),
...createGlobPatternsForDependencies(__dirname),
],
theme: {
extend: {},
},
plugins: [],
};
10 changes: 10 additions & 0 deletions apps/angular/52-lazy-load-component/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": []
},
"files": ["src/main.ts"],
"include": ["src/**/*.d.ts"],
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
}
6 changes: 6 additions & 0 deletions apps/angular/52-lazy-load-component/tsconfig.editor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {},
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
}
33 changes: 33 additions & 0 deletions apps/angular/52-lazy-load-component/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.editor.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
15 changes: 15 additions & 0 deletions apps/angular/52-lazy-load-component/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node", "@testing-library/jest-dom"]
},
"files": ["src/test-setup.ts"],
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
4 changes: 2 additions & 2 deletions challenge-number.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"total": 51,
"🟢": 20,
"total": 52,
"🟢": 21,
"🟠": 121,
"🔴": 209
}
6 changes: 6 additions & 0 deletions docs/src/content/authors/lance-finney.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Lance Finney",
"twitter": "https://twitter.com/LMFinneyCoder",
"linkedin": "https://www.linkedin.com/in/lmfinney/",
"github": "https://github.com/LMFinney"
}
Loading

0 comments on commit c8ba057

Please sign in to comment.