This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ResourceOptions<T> { | |
query: () => Observable<T> | Promise<T>; | |
} | |
interface Resource<T> { | |
query: () => void; | |
data: Signal<T>; | |
state: Signal<'IDLE' | 'PROCESSING' | 'EMITTING' | 'COMPLETE'>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SignalHttpService { | |
constructor(private httpClient: HttpClient) {} | |
getSomeData() { | |
const result = signal(null); | |
this.httpClient.get(url).subscribe(data => result.set(data)); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// minimal working dependency injection | |
// the dependency injection works with a property based injection | |
const clazzMap = Symbol('clazzMap'); | |
globalThis[clazzMap] = new Map(); // <clazz, instance> | |
const clazzes = Symbol('clazzes') | |
globalThis[clazzes] = []; | |
function register(clazz) { | |
globalThis[clazzes].push(clazz); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, computed, Signal, signal, WritableSignal } from '@angular/core'; | |
import { bootstrapApplication } from '@angular/platform-browser'; | |
import { FormsModule } from '@angular/forms'; | |
import { NgFor } from '@angular/common'; | |
@Component({ | |
selector: 'app-root', | |
standalone: true, | |
imports: [ | |
NgFor, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// belongs to SpecialModule which is a generic lib, every App needs to provide their implementation of UserService. | |
// The lib uses this special implementation as UserService internally | |
abstract class UserService { | |
} | |
@Injectable() | |
class SpecialService { | |
constructer(private userService: UserService) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@customElement('my-element') | |
export class MyElement extends LitElement { | |
@property({ | |
hasChanged(newVal: number, oldVal: number) { | |
const hasChanged: boolean = newVal !== oldVal; | |
console.log(`${newVal}, ${oldVal}, ${hasChanged}`); | |
return hasChanged; | |
}, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-template *ngIf="stream$ | async as result"> | |
<div>{{result}} can be an empty string</div> | |
</ng-template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple German normalize | |
function normalizeIt(str) { | |
const normalized = str.normalize('NFC') | |
.toLocaleUpperCase() | |
.trim() | |
.replace(/Ä/g, 'AE' ) | |
.replace(/Ö/g, 'OE' ) | |
.replace(/Ü/g, 'UE' ) | |
.replace(/ß/g, 'SS' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference lib="webworker" /> | |
interface IMessageEvent<T> { | |
name: string; | |
payload: T; | |
} | |
function PostMessage(eventName: string) { | |
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { | |
const originalMethod = descriptor.value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function booleanArrayToHex(arr) { | |
const binaryString = arr.map(it => it ? '1' : '0').join(''); | |
return parseInt(binaryString, 2).toString(16).toUpperCase(); | |
} | |
function hexToBooleanArray(hex, arrayLength = 16){ | |
const binaryString = (parseInt(hex, 16).toString(2)).padStart(arrayLength, '0'); | |
return binaryString.split('').map(it => it === '1'); | |
} |
NewerOlder