Skip to content

Instantly share code, notes, and snippets.

View eneajaho's full-sized avatar
🏠
Working from home

Enea Jahollari eneajaho

🏠
Working from home
View GitHub Profile
@eneajaho
eneajaho / inject-destroy.ts
Created August 11, 2023 13:45
Inject Destroy
import { DestroyRef, inject } from '@angular/core';
import { ReplaySubject } from 'rxjs';
/**
* Injects the `DestroyRef` service and returns a `ReplaySubject` that emits
* when the component is destroyed.
*
* @throws {Error} If no `DestroyRef` is found.
* @returns {ReplaySubject<void>} A `ReplaySubject` that emits when the component is destroyed.
*
@eneajaho
eneajaho / settings.json
Last active December 14, 2023 20:21
My VSCode settings
{
"editor.fontWeight": 400,
"editor.fontSize": 16,
"editor.lineHeight": 2,
"editor.quickSuggestionsDelay": 0,
"editor.inlineSuggest.enabled": true,
"editor.bracketPairColorization.independentColorPoolPerBracketType": true,
"editor.foldingImportsByDefault": true,
@eneajaho
eneajaho / regenereate-cache.module.ts
Last active November 8, 2022 16:17
Vendure Admin Regenerate cache button
```ts
import { NgModule } from '@angular/core';
import { SharedModule, addActionBarItem } from '@vendure/admin-ui/core';
import { take } from 'rxjs/operators';
@NgModule({
imports: [ SharedModule ],
providers: [
addActionBarItem({
id: 'isr-regenerate-cache',
@eneajaho
eneajaho / when-to-use-memo.ts
Created September 29, 2022 08:07
When to use memo
@Component({
selector: "app-root",
template: `
<div>{{ isOdd(count) }}</div>
<div>{{ isOdd(count) }}</div>
<div>{{ isOdd(count) }}</div>
<button (click)="count = count + 1">Increase</button>
`,
standalone: true,
})
@eneajaho
eneajaho / when-not-to-use-memo.ts
Created September 29, 2022 08:03
When not to use memo
@Component({
selector: "app-root",
template: `
<div>{{ isOdd(count) }}</div>
<div>{{ isOdd(count + 1) }}</div>
<div>{{ isOdd(count + 2) }}</div>
<button (click)="count = count + 1">Increase</button>
`,
standalone: true,
})
@eneajaho
eneajaho / component-using-memo-function.ts
Last active September 28, 2022 13:52
A component using memo function
@Component({
selector: "app-root",
template: `
<div>{{ plusOne(count) }}</div>
<button (click)="count = count + 1">Increase</button>
`,
standalone: true
})
export class AppComponent {
count = 0;
@eneajaho
eneajaho / memo.ts
Created September 28, 2022 13:38
Memo function
export function memo<T extends Function>(fnToMemoize: T): T {
let prevArgs = [{}];
let result;
return function (...newArgs) {
if (hasDifferentArgs(prevArgs, newArgs)) {
result = fnToMemoize(...newArgs);
prevArgs = newArgs;
}
return result;
@eneajaho
eneajaho / component-with-pipe-generated-code.ts
Last active September 28, 2022 16:02
Angular component with pipe (generated code)
class PlusOnePipe {
transform(value) { return value + 1; }
}
PlusOnePipe.ɵfac = function PlusOnePipe_Factory(t) {
return new (t || PlusOnePipe)();
};
PlusOnePipe.ɵpipe = ɵɵdefinePipe({
name: "plusOne",
@eneajaho
eneajaho / component-with-pipe.ts
Last active September 28, 2022 12:46
Angular component with pipe (user code)
@Pipe({ name: 'plusOne', standalone: true })
export class PlusOnePipe implements PipeTransform {
transform(value: number): number {
return value + 1;
}
}
@Component({
selector: "app-root",
template: `
@eneajaho
eneajaho / nx-structure-angular-nestjs.md
Created March 3, 2022 14:30 — forked from trungvose/nx-structure-angular-nestjs.md
Nx workspace structure for NestJS and Angular

Nx

https://nx.dev/

Nx is a suite of powerful, extensible dev tools to help you architect, test, and build at any scale — integrating seamlessly with modern technologies and libraries while providing a robust CLI, caching, dependency management, and more.

It has first-class support for many frontend and backend technologies, so its documentation comes in multiple flavours.

Principles