Skip to content

Instantly share code, notes, and snippets.

@antischematic
antischematic / class.ts
Last active September 6, 2021 09:26
Class vs Function composition
@Component({
template: `
<div>
<show-results *ngIf="results$ | async as results else loading" [results]="results"></show-results>
<ng-template #loading>
<spinner></spinner>
</ng-template>
</div>
<pagination [page]="page" [pageSize]="10" [total]="(results$ | async)?.length""></pagination>
@antischematic
antischematic / counter.component.compiled.ts
Last active February 21, 2022 15:12
Angular Single File Module
// noinspection BadExpressionStatementJS
import {
use,
inject,
listen,
subscribe, provide, ValueToken, ViewDef,
} from "@mmuscat/angular-composition-api"
import { EMPTY } from "rxjs"
import { Component, ViewChild } from "@angular/core"
@antischematic
antischematic / reactivity-core.ts
Last active August 29, 2022 12:50
Angular Reactivity Thought Experiment
interface ActionConfig {
// enables or disables default proxy-based dependency tracking on `this`
// default: false
track?: boolean
// whether the action should be executed on init
// this option is ignored if function.length > 0
// default: false
immediate?: boolean
// run action during ngDoCheck when dependencies change
@antischematic
antischematic / angular.ts
Last active October 22, 2022 00:13
ng-what-if
// https://github.com/antischematic/angular-state-library
function loadTodos(userId, reload) {
return inject(HttpClient).get(endpoint, { params: { userId }}).pipe(
retry({ delay: () => reload })
)
}
@Component({
template: `
class User {
constructor(public name: string) {}
toString() {
return this.name
}
}
///
@antischematic
antischematic / cypress.config.ts
Last active June 18, 2023 06:00
Polly setup with leftest-cypress
import { defineConfig } from "cypress"
import { setupPollyTasks } from "./src/support/polly-tasks"
export default defineConfig({
e2e: {
supportFile: "**/support/e2e.{js,jsx,ts,tsx}",
specPattern: "**/app.cy.ts",
testIsolation: false,
setupNodeEvents(on) {
setupPollyTasks(on)
import { ComponentHarness, HarnessEnvironment, TestElement, ComponentHarnessConstructor, ElementDimensions, TestKey, ModifierKeys} from "@angular/cdk/testing"
import { Locator, Page, test, expect as baseExpect } from "@playwright/test"
/**
* An Angular framework stabilizer function that takes a callback and calls it when the application
* is stable, passing a boolean indicating if any work was done.
*/
declare interface FrameworkStabilizer {
(callback: (didWork: boolean) => void): void;
}