Skip to content

Instantly share code, notes, and snippets.

View armanozak's full-sized avatar

Levent Arman Özak armanozak

View GitHub Profile
@armanozak
armanozak / app.component.ts
Last active May 9, 2019 08:30
Angular Context - Two-way Data-binding (#2) #blog
@Component({
selector: 'my-app',
template: `
<context-provider provide="rate onRating">
<two-way></two-way>
</context-provider>
{{ rate }}
`,
})
@armanozak
armanozak / two-way.component.ts
Last active May 9, 2019 08:30
Angular Context - Two-way Data-binding (#3) #blog
@Component({
selector: 'two-way',
template: `
<ng-template
contextDisposer="rate onRating"
let-rate="rate"
let-onRating="onRating"
>
<rating
[ngModel]="rate"
@armanozak
armanozak / app.component.ts
Last active May 9, 2019 08:30
Angular Context - Two-way Data-binding (#4) #blog
@Component({
selector: 'my-app',
template: `
<form [formGroup]="form">
<context-provider provide="rate">
<two-way></two-way>
</context-provider>
</form>
{{ rate }}
@armanozak
armanozak / card-image.component.ts
Last active November 4, 2019 12:22
Adaptive Components - Dumb Card Image Component #blog
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
@Component({
selector: 'app-card-image',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<img [alt]="alt" [src]="src" [ngClass]="classes" (load)="ready = true" />
<span *ngIf="ready && attribution">
Image by <a [href]="attribution.href">{{ attribution.text }}</a>
</span>
@armanozak
armanozak / card-image.component.ts
Last active November 8, 2019 08:05
Adaptive Components - Not-So-Dumb Card Image Component #blog
import {
ChangeDetectionStrategy,
Component,
Input,
Optional,
} from '@angular/core';
import { CardVerticalComponent } from './card-vertical.component';
@Component({
selector: 'app-card-image',
@armanozak
armanozak / abstract-card.ts
Created November 5, 2019 10:25
Adaptive Components - Card Components and How They Are Consumed #blog
import { ContentChild, ElementRef, Input } from '@angular/core';
import { CardTitleComponent } from './card-title.component';
export abstract class AbstractCard {
@Input() action = () => {};
@Input() color = 'primary';
}
@armanozak
armanozak / card-title.component.ts
Created November 5, 2019 11:16
Adaptive Components - Using :host-context Selector to Set a Style Based on Context #blog
import { ChangeDetectionStrategy, Component } from '@angular/core';
@Component({
selector: 'app-card-title',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h5 class="card-title">
<ng-content></ng-content>
</h5>
`,
@armanozak
armanozak / card-button.component.ts
Last active November 10, 2019 09:56
Adaptive Components - Using Properties on Parent Component in Angular #blog
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { AbstractCard } from './abstract-card';
import { CardHorizontalComponent } from './card-horizontal.component';
@Component({
selector: 'app-card-button',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<button class="btn" [ngClass]="classes" (click)="parent.action()">
<ng-content></ng-content>
@armanozak
armanozak / keybindings.json
Last active December 16, 2020 11:07
[Disabling TS Lint, The Easy Way] VS Code Snippet + Key Binding for Adding TS Lint Rule Flags #typescript #vscode #tip
// /User/keybindings.json
[
{
"key": "shift+alt+t",
"command": "editor.action.insertSnippet",
"when": "resourceLangId == typescript && editorTextFocus && !editorReadonly",
"args": {
"langId": "typescript",
"name": "Disable TSLint"
@armanozak
armanozak / deep-boolean.ts
Created January 1, 2020 21:03
[Callable Constructors in TypeScript] How to Merge Ambient Class Declaration with Function Declaration #typescript #tips
// requires TypeScript v3.6+
export { DeepBoolean };
type Mutable<T> = {
-readonly [P in keyof T]: T[P];
};
declare class DeepBoolean<T = any> {
constructor(source: T);