Skip to content

Instantly share code, notes, and snippets.

Avatar

Rainer Hahnekamp rainerhahnekamp

View GitHub Profile
@rainerhahnekamp
rainerhahnekamp / selector with deep equal
Created Oct 21, 2022
NgRx selector with customized equal function
View selector with deep equal
import { isEqual } from 'lodash';
import {
createFeatureSelector,
createSelector,
createSelectorFactory,
defaultMemoize,
} from '@ngrx/store';
import * as fromFlightBooking from './flight-booking.reducer';
export const selectFlightBookingState = createFeatureSelector<
View init.spec.ts
import { test, expect } from '@playwright/test';
test.describe('initial test', () => {
test('holidays', async ({ page }) => {
await page.goto('https://genuine-narwhal-f0f8ad.netlify.app/');
await page.click('[data-testid=btn-holidays]');
await expect(page.locator('mat-drawer-content')).toContainText(
'Choose among our Holidays'
);
View scheduler.spec.ts
import { Component } from '@angular/core';
import { fakeAsync, flush, TestBed } from '@angular/core/testing';
import {
SchedulerEvent,
SchedulerModule,
} from '@progress/kendo-angular-scheduler';
const baseData: any[] = [
{
TaskID: 4,
View customer.actions.ts
const removed = createAction(
'[CUSTOMER] Removed',
props<{ customers: Customer[] }>()
);
// further actions (removed here for simplicity reasons)
export const CustomerActions = {
get,
View index.ts
export * from './lib/customer-data.module';
export { PublicCustomerActions as CustomerActions } from './lib/customer.actions';
export * from './lib/customer.selectors';
View edit-customer.component.ts
@Component({
selector: 'eternal-edit-customer',
template: ` <eternal-customer
*ngIf="customer$ | async as customer"
[customer]="customer"
(save)="this.submit($event)"
(remove)="this.remove($event)"
></eternal-customer>`,
})
export class EditCustomerComponent implements OnInit {
View customer.component.ts
export class CustomerComponent {
formGroup = new FormGroup({});
@Input() customer: Customer | undefined;
@Output() save = new EventEmitter<Customer>();
@Output() remove = new EventEmitter<Customer>();
fields: FormlyFieldConfig[] = [
// form configuration
];
View data.guard.ts
@Injectable({
providedIn: 'root',
})
export class DataGuard implements CanActivate {
constructor(private store: Store<CustomerAppState>) {}
canActivate(): Observable<boolean> {
this.store.dispatch(CustomerActions.get());
return this.store
.select(fromCustomer.isLoaded)
View reducer.ts
export interface State {
customers: Customer[];
}
const initialState = {
customers: []
}
View reducer.ts
export interface State {
loadStatus: 'NOT_LOADED' | 'LOADING' | 'LOADED';
customers: Customer[];
}
const initialState = {
loadStatus: 'NOT_LOADED',
customers: []
}