Skip to content

Instantly share code, notes, and snippets.

View adrianfaciu's full-sized avatar
🎯
Focusing

Adrian Fâciu adrianfaciu

🎯
Focusing
View GitHub Profile
import { NgModule } from '@angular/core'
import { ToastComponent } from './toast.component';
@NgModule({
declarations: [ToastComponent],
entryComponents: [ToastComponent]
})
export class ToastModule { }
import { Component } from '@angular/core';
@Component({
selector: 'app-toast',
template: `
<div>This is a toast message</div>
`
})
export class ToastComponent { }
loadDocuments$ = this.actions$.pipe(
ofType<documentActions.Fetch>(documentActions.FETCH)
switchMap((action) =>
this.documentsService
.getDocuments().pipe(
map(docs => new documentActions.FetchSuccess(docs)),
catchError(error => of(
new ErrorOccurred({
action,
error,
export function reducer(state = initialState, action: AuthActionsUnion): State {
switch (action.type) {
case AuthActionTypes.LoginSuccess: {
return {
...state,
loggedIn: true,
user: action.payload.user,
};
}
export class ErrorOccurred implements Action {
readonly type = ERROR_OCCURRED;
constructor(
readonly payload: {
action?: Action;
error?: ErrorData;
},
) {}
}
export class DocumentContainer {
companyName$ = this.store.select(detailsSelector.getDocumentCompanyName);
documentStatus$ = this.store.select(detailsSelector.getDocumentStatus);
constructor(private store: Store<AppStore.AppState>) { }
}
export class DocumentContainer {
companyName$: Observable<string>;
documentStatus$: Observable<number>;
constructor(
private store: Store<AppStore.AppState>,
) {
this.companyName$ = this.store.select(detailsSelector.getDocumentCompanyName);
this.documentStatus$ = this.store.select(detailsSelector.getDocumentStatus);
import { Action } from '@ngrx/store';
export const LOG_ERROR = '[Logger] Log Error';
export const LOG_WARNING = '[Logger] Log Warning';
export const LOG_INFO = '[Logger] Log Info';
export class LogError implements Action {
readonly type = LOG_ERROR;
constructor(readonly payload: { message: string }) { }
}
class Point {
constructor(public point: number) {}
}
function creator<T, G>(type: { new (args: G): T }) {
return (args: G) => new type(args);
}
[1, 2, 3].map(creator(Point));
import { Directive, HostListener, ElementRef } from '@angular/core';
import { Router } from '@angular/router';
import { isNil } from 'ramda';
@Directive({
selector: 'a[appExternalUrl]',
})
export class ExternalUrlDirective {
constructor(private el: ElementRef, private router: Router) {}