Skip to content

Instantly share code, notes, and snippets.

View off-sky's full-sized avatar

offsky off-sky

View GitHub Profile
@off-sky
off-sky / main-behaviour-subject.ts
Created March 6, 2024 20:05
Angular state management - BehaviorSubject example
interface AppState {
currentQuery: string | null;
status: 'idle' | 'loading' | 'error';
results: string[];
}
@Component({
selector: 'app-root',
standalone: true,
@off-sky
off-sky / main-component-store.ts
Created March 6, 2024 19:46
Angular state management - Component store example
interface AppState {
currentQuery: string | null;
status: 'idle' | 'loading' | 'error';
results: string[];
}
@Component({
selector: 'app-root',
standalone: true,
@off-sky
off-sky / main-reactive-imperative-blend.ts
Created March 5, 2024 19:03
Angular state management example - Reactive-imperative blend
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule],
template: `
<input placeholder="Your query" style="margin-right: 10px" (input)="onInput($event)">
<button [disabled]="isSearchDisabled$ | async" (click)="onSearchClicked()">Search</button>
<div *ngIf="displayStatus$ | async; let displayStatus">
{{ displayStatus }}
</div>
@off-sky
off-sky / main-ngrx.ts
Created March 1, 2024 19:10
Angular State Management - NGRX example
// actions
const searchInput = createAction(
'[App]: Search input',
props<{ value: string }>()
);
const searchButtonClicked = createAction('[App]: Search button clicked');
const searchSuccess = createAction(
'[Effect]: Search success',
props<{ results: string[] }>()
);
@off-sky
off-sky / main-reactive.ts
Last active March 8, 2024 08:55
Angular state management - Reactive example
@Component({
selector: 'app-root',
standalone: true,
template: `
<input placeholder="Your query" style="margin-right: 10px" #inputElement>
<button [disabled]="isSearchDisabled$ | async" #buttonElement>Search</button>
<div *ngIf="displayStatus$ | async; let displayStatus">
{{ displayStatus }}
</div>
<div *ngIf="results$ | async; let results">
@off-sky
off-sky / main.ts
Last active February 29, 2024 19:23
Angular state management - Good ol' imperative example
@Component({
selector: 'app-root',
standalone: true,
template: `
<input placeholder="Your query" style="margin-right: 10px" (input)="onInput($event)">
<button [disabled]="isSearchDisabled" (click)="onSearch()">Search</button>
<div *ngIf="displayStatus">
{{ displayStatus }}
</div>
<div *ngIf="results">
@off-sky
off-sky / get-positions-from-input-parameters.ts
Last active July 4, 2022 12:51
Get connected position from input parameters
export const getPositionsFromInputParameters = (
xPosition: 'above' | 'center' | 'below',
yPosition: 'before' | 'center' | 'after' | 'align-start' | 'align-end',
): ConnectedPosition[] => {
const primaryPosition = getPrimaryPositionFromInputParameters(xPosition, yPosition);
return [primaryPosition, ...getFallBackPositionsForPrimaryPosition(primaryPosition)];
};
@off-sky
off-sky / custom-tooltip.component.ts
Last active July 4, 2022 07:39
custom tooltip component
@Component({
selector: 'custom-tooltip',
template: `
<div
cdkOverlayOrigin
#trigger="cdkOverlayOrigin"
(mouseenter)="mouseEnter()"
(mouseleave)="mouseLeave()"
>
@off-sky
off-sky / global.css
Created July 4, 2022 07:21
Include overlay cdk styles
@import '@angular/cdk/overlay-prebuilt.css';
@off-sky
off-sky / some.html
Created July 4, 2022 07:13
Custom tooltip usage
<custom-tooltip xPosition="center" yPosition="top">
<div anchor>
Hover over me.
</div>
<div content>
<h3>Awesome header</h3>
<div>Awesome text</div>
</div>
</custom-tooltip>