Skip to content

Instantly share code, notes, and snippets.

View 7jpsan's full-sized avatar
💭
https://jpsan.co.uk

Paulo Soares 7jpsan

💭
https://jpsan.co.uk
View GitHub Profile
function replace(template: string, replacements: string[]) {
const initialState = {
result: '',
valid: true,
openGroup: false,
previous: '',
index: 0,
};
return template.split('').reduce((acc, next) => {
@7jpsan
7jpsan / run-on-push-change-detection.ts
Created September 5, 2019 19:09
Runs Angular 7 change detection when the component uses onPush strategy
import { ChangeDetectorRef } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';
export async function runOnPushChangeDetection<T>(cf: ComponentFixture<T>) {
const cd = cf.debugElement.injector.get<ChangeDetectorRef>(
// tslint:disable-next-line:no-any
ChangeDetectorRef as any
);
cd.detectChanges();
await cf.whenStable();
@7jpsan
7jpsan / url-template-service.ts
Last active June 6, 2019 17:19
Typescript string template engine
import { cloneDeep } from 'lodash';
class UrlTemplateService {
private readonly urlsMap = {
serviceA: {
example1: (p: { customerCode: string }) => this.replace('one.parameter/${customerCode}', p),
pathB: (p: { more: string, parameter: string }) => this.replace('two.more.example/${more}/${parameter}/${more}', p)
},
serviceB: {