Skip to content

Instantly share code, notes, and snippets.

View e-oz's full-sized avatar
πŸ•ŠοΈ

Evgeniy OZ e-oz

πŸ•ŠοΈ
View GitHub Profile
import { Component, signal } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { IfHasPermissionDirective } from './if-has-permission.directive';
import { Permission, PermissionsService } from '../permissions.service';
const $allowedPermissions = signal<Permission[]>([]);
class PermissionsServiceMock {
hasPermission(permission: Permission) {
return $allowedPermissions().includes(permission);
import { inject, TemplateRef, ViewContainerRef } from "@angular/core";
export abstract class StructuralConditionalDirective {
protected readonly templateRef = inject(TemplateRef<any>);
protected readonly viewContainer = inject(ViewContainerRef);
protected elseTemplateRef: TemplateRef<any> | undefined = undefined;
protected hasView: boolean = false;
protected hasElseView: boolean = false;
protected condition: boolean = false;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import { assertInInjectionContext, DestroyRef, inject, Injector, isDevMode, isSignal, type Signal } from '@angular/core';
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
import { isObservable, Observable, of, retry, type RetryConfig, Subject, Subscription } from 'rxjs';
export type CreateEffectOptions = {
injector?: Injector,
/**
* @param retryOnError
* Set to 'false' to disable retrying on error.
* Otherwise, generated effect will use `retry()`.
@e-oz
e-oz / main.ts
Created December 26, 2022 13:00
NgZone optimisations for Angular CDK Drag & Drop
platformBrowserDynamic().bootstrapModule(AppModule, {
ngZoneEventCoalescing: true,
ngZoneRunCoalescing: true,
}).catch((err) => console.error(err));
@e-oz
e-oz / viva-magenta.scss
Created December 2, 2022 11:53
Viva Magenta - Angular Material Palette
$dark-primary-text: rgba(0, 0, 0, 0.87);
$light-primary-text: rgb(255, 255, 255);
$viva-magenta: (
50 : #f7e5e9,
100 : #ebbec8,
200 : #dd93a4,
300 : #cf6780,
400 : #c54764,
500 : #bb2649,
@e-oz
e-oz / input.ts
Created September 20, 2022 12:32
export class SomeComponent {
@Input() set field(field: someType) {
this.store.patchState({field});
}
}
libs/feature/src:
└─ lib
β”œβ”€ example
β”‚ β”œβ”€ example.component.html
β”‚ β”œβ”€ [example.component.scss]
β”‚ β”œβ”€ example.component.spec.ts
β”‚ β”œβ”€ example.component.ts
β”‚ β”œβ”€ [example.store.ts]
β”‚ └─ [README.md]
└─ [README.md]
interface UsersListState {
users: User[];
columns: string[];
}
class UsersListStore extends ComponentStore<UsersListState> {
// ...
getUsers() {
return this.select(state => state.users).pipe(
combineLatestWith(this.select(state => state.columns)),
map(([users, columns]) => {
class UploaderConfig {
public readonly url: string;
}
// Service, where you need UploaderConfig
class ApiService {
constructor(@Inject('UPLOADER_CONFIG') config: UploaderConfig){
}
}
// Module or component where you can configure dependencies: