Skip to content

Instantly share code, notes, and snippets.

import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { ErrorDto } from '@models/error';
import {
Auth,
CreateLoginDto,
@whisher
whisher / gist:1e6822400451938fdc78ed926ef2f8d2
Last active April 25, 2023 17:55
Ngrx ActionReducerMap example
import { ActionReducerMap } from '@ngrx/store';
import {
userAddressesReducer,
UserAddressesState
} from './user-addresses.reducer';
import { userProfileReducer, UserProfileState } from './user-profile.reducer';
export interface UserState {
addresses: UserAddressesState;
profile: UserProfileState;
}
@whisher
whisher / gist:69a401f40e6534b1d7d7355de77f565e
Last active August 13, 2019 21:06
Ngrx combineReducers example
import { combineReducers } from '@ngrx/store';
import {
userAddressesReducer,
UserAddressesState,
initialUserAddressesState
} from './user-addresses.reducer';
import {
userProfileReducer,
UserProfileState,
postAccountUpdateProducts(
products: MarketAccountUpdateProductDto[]
): Observable<MarketAccountCompleteDto | null> {
return this.facade.data$.pipe(
switchMap((dto: MarketAccountCompleteDto | null) => {
if (dto) {
const data: MarketAccountUpdateProductsDto = {
user: dto.account,
products
};
UPDATE
createForm() {
this.frm = this.fb.group({
delivery: this.delivery,
invoice: this.invoice
});
this.frm.get('invoice').disable();
}
show() {
checkStore(): Observable<boolean> {
return this.store.select(fromStore.selectDishesLoaded).pipe(
tap(loaded => {
if (!loaded) {
this.store.dispatch(new fromStore.LoadDishes());
}
}),
take(1)
);
}
export abstract class BaseComponent implements OnDestroy {
private subscriptions: Array<Subscription> = [];
ngOnDestroy() {
this.subscriptions.forEach(sub => sub.unsubscribe());
}
public subscription(subscription: Subscription) {
this.subscriptions.push(subscription);
export function ifExists<T>(obj: T | null | undefined, callback: (obj: T) => void) {
if (exists(obj)) {
callback(obj as T);
}
}
addCurrency(currencyType: Currency, amount: number) {
obj.ifExists(this.model, (dto) => {
for (const currency of dto.currency) {
if (currency.first === currencyType) {
import { Injectable } from '@angular/core';
import { TranslateService, LangChangeEvent } from '@ngx-translate/core';
import { Logger } from '../logger';
import enUS from '../../../translations/en-US.json';
import itIT from '../../../translations/it-IT.json';
const log = new Logger('I18nService');
import React from "react"
import { graphql } from "gatsby"
import Img from "gatsby-image"
const Image = ({ data }) => (
<div>
<h1>Hello gatsby-image</h1>
{console.log(data)}
<Img fluid={data.file.childImageSharp.fluid} />
</div>