diff --git a/apps/performance/memoized/.eslintrc.json b/apps/performance/memoized/.eslintrc.json new file mode 100644 index 0000000..bf8df14 --- /dev/null +++ b/apps/performance/memoized/.eslintrc.json @@ -0,0 +1,36 @@ +{ + "extends": ["../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts"], + "rules": { + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "app", + "style": "camelCase" + } + ], + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "app", + "style": "kebab-case" + } + ] + }, + "extends": [ + "plugin:@nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ] + }, + { + "files": ["*.html"], + "extends": ["plugin:@nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/performance/memoized/README.md b/apps/performance/memoized/README.md new file mode 100644 index 0000000..f16afc0 --- /dev/null +++ b/apps/performance/memoized/README.md @@ -0,0 +1,32 @@ +

memoized function

+ +> Author: Thomas Laforge + + + +### Information + +### Statement + +### Step 1 + +### Step 2 + +### Constraints: + +### Submitting your work + +1. Fork the project +2. clone it +3. npm ci +4. `npx nx serve memoized` +5. _...work on it_ +6. Commit your work +7. Submit a PR with a title beginning with **Answer:35** that I will review and other dev can review. + +memoized +memoized solution author + + + +_You can ask any question on_ twitter diff --git a/apps/performance/memoized/project.json b/apps/performance/memoized/project.json new file mode 100644 index 0000000..5b8da20 --- /dev/null +++ b/apps/performance/memoized/project.json @@ -0,0 +1,85 @@ +{ + "name": "performance-memoized", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "prefix": "app", + "sourceRoot": "apps/performance/memoized/src", + "tags": [], + "targets": { + "build": { + "executor": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/apps/performance/memoized", + "index": "apps/performance/memoized/src/index.html", + "main": "apps/performance/memoized/src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "apps/performance/memoized/tsconfig.app.json", + "assets": [ + "apps/performance/memoized/src/favicon.ico", + "apps/performance/memoized/src/assets" + ], + "styles": [ + "apps/performance/memoized/src/styles.scss", + "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css" + ], + "scripts": [], + "allowedCommonJsDependencies": ["seedrandom"] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb", + "maximumError": "1mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb", + "maximumError": "4kb" + } + ], + "outputHashing": "all" + }, + "development": { + "buildOptimizer": false, + "optimization": false, + "vendorChunk": true, + "extractLicenses": false, + "sourceMap": true, + "namedChunks": true + } + }, + "defaultConfiguration": "production" + }, + "serve": { + "executor": "@angular-devkit/build-angular:dev-server", + "configurations": { + "production": { + "browserTarget": "performance-memoized:build:production" + }, + "development": { + "browserTarget": "performance-memoized:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "executor": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "performance-memoized:build" + } + }, + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "apps/performance/memoized/**/*.ts", + "apps/performance/memoized/**/*.html" + ] + } + } + } +} diff --git a/apps/performance/memoized/src/app/app.component.ts b/apps/performance/memoized/src/app/app.component.ts new file mode 100644 index 0000000..01d0493 --- /dev/null +++ b/apps/performance/memoized/src/app/app.component.ts @@ -0,0 +1,28 @@ +import { NgIf } from '@angular/common'; +import { Component } from '@angular/core'; +import { generateList } from './generateList'; +import { PersonListComponent } from './person-list.component'; + +@Component({ + standalone: true, + imports: [PersonListComponent, NgIf], + selector: 'app-root', + template: ` +

Performance is key!!

+ + + + `, +}) +export class AppComponent { + persons = generateList(); + loadList = false; +} diff --git a/apps/performance/memoized/src/app/app.config.ts b/apps/performance/memoized/src/app/app.config.ts new file mode 100644 index 0000000..59198e6 --- /dev/null +++ b/apps/performance/memoized/src/app/app.config.ts @@ -0,0 +1,6 @@ +import { ApplicationConfig } from '@angular/core'; +import { provideAnimations } from '@angular/platform-browser/animations'; + +export const appConfig: ApplicationConfig = { + providers: [provideAnimations()], +}; diff --git a/apps/performance/memoized/src/app/generateList.ts b/apps/performance/memoized/src/app/generateList.ts new file mode 100644 index 0000000..62978ec --- /dev/null +++ b/apps/performance/memoized/src/app/generateList.ts @@ -0,0 +1,15 @@ +import { randFirstName, randNumber } from '@ngneat/falso'; +import { Person } from './person.model'; + +export function generateList() { + const arr: Person[] = []; + + for (let i = 0; i < 100; i++) { + arr.push({ + name: randFirstName(), + fib: randNumber({ min: 25, max: 30, precision: 1 }), + }); + } + + return arr; +} diff --git a/apps/performance/memoized/src/app/person-list.component.ts b/apps/performance/memoized/src/app/person-list.component.ts new file mode 100644 index 0000000..1f8ae15 --- /dev/null +++ b/apps/performance/memoized/src/app/person-list.component.ts @@ -0,0 +1,64 @@ +import { Component, Input } from '@angular/core'; + +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import { MatChipsModule } from '@angular/material/chips'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { MatListModule } from '@angular/material/list'; +import { Person } from './person.model'; + +const fibonacci = (num: number): number => { + if (num === 1 || num === 2) { + return 1; + } + return fibonacci(num - 1) + fibonacci(num - 2); +}; + +@Component({ + selector: 'app-person-list', + standalone: true, + imports: [ + CommonModule, + FormsModule, + MatListModule, + MatFormFieldModule, + MatInputModule, + MatChipsModule, + ], + template: ` +

+ {{ title | titlecase }} +

+ + + + + + + +
+

{{ person.name }}

+ {{ calculate(person.fib) }} +
+
+
+ `, + host: { + class: 'w-full flex flex-col items-center', + }, +}) +export class PersonListComponent { + @Input() persons: Person[] = []; + @Input() title = ''; + + label = ''; + + calculate(num: number) { + return fibonacci(num); + } +} diff --git a/apps/performance/memoized/src/app/person.model.ts b/apps/performance/memoized/src/app/person.model.ts new file mode 100644 index 0000000..cac730d --- /dev/null +++ b/apps/performance/memoized/src/app/person.model.ts @@ -0,0 +1,4 @@ +export interface Person { + name: string; + fib: number; +} diff --git a/apps/performance/memoized/src/assets/.gitkeep b/apps/performance/memoized/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/performance/memoized/src/favicon.ico b/apps/performance/memoized/src/favicon.ico new file mode 100644 index 0000000..317ebcb Binary files /dev/null and b/apps/performance/memoized/src/favicon.ico differ diff --git a/apps/performance/memoized/src/index.html b/apps/performance/memoized/src/index.html new file mode 100644 index 0000000..459031f --- /dev/null +++ b/apps/performance/memoized/src/index.html @@ -0,0 +1,13 @@ + + + + + performance-memoized + + + + + + + + diff --git a/apps/performance/memoized/src/main.ts b/apps/performance/memoized/src/main.ts new file mode 100644 index 0000000..514c89a --- /dev/null +++ b/apps/performance/memoized/src/main.ts @@ -0,0 +1,7 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { appConfig } from './app/app.config'; +import { AppComponent } from './app/app.component'; + +bootstrapApplication(AppComponent, appConfig).catch((err) => + console.error(err) +); diff --git a/apps/performance/memoized/src/styles.scss b/apps/performance/memoized/src/styles.scss new file mode 100644 index 0000000..77e408a --- /dev/null +++ b/apps/performance/memoized/src/styles.scss @@ -0,0 +1,5 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/performance/memoized/tailwind.config.js b/apps/performance/memoized/tailwind.config.js new file mode 100644 index 0000000..38183db --- /dev/null +++ b/apps/performance/memoized/tailwind.config.js @@ -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: [], +}; diff --git a/apps/performance/memoized/tsconfig.app.json b/apps/performance/memoized/tsconfig.app.json new file mode 100644 index 0000000..5822042 --- /dev/null +++ b/apps/performance/memoized/tsconfig.app.json @@ -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"] +} diff --git a/apps/performance/memoized/tsconfig.editor.json b/apps/performance/memoized/tsconfig.editor.json new file mode 100644 index 0000000..4ee6393 --- /dev/null +++ b/apps/performance/memoized/tsconfig.editor.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": { + "types": [] + } +} diff --git a/apps/performance/memoized/tsconfig.json b/apps/performance/memoized/tsconfig.json new file mode 100644 index 0000000..51c7908 --- /dev/null +++ b/apps/performance/memoized/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "target": "es2022", + "useDefineForClassFields": false, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.app.json" + }, + { + "path": "./tsconfig.editor.json" + } + ], + "extends": "../../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +}