Run task npm:install:app
after this
cd env/api && npm install --silent
export class ReplayControlValueChanges<T> extends Observable<T> { | |
constructor(control: AbstractControl | AbstractControlDirective) { | |
super(subscriber => { | |
if (!control.valueChanges) { | |
throw new Error('Control does not have valueChanges'); | |
} | |
control.valueChanges.pipe(startWith(control.value)).subscribe(subscriber); | |
}); | |
} |
type ValidationResult<T, U> = Partial<{ [Key in keyof T]: U }>; | |
type Validation<T, U> = (fields: T) => ValidationResult<T, U>; | |
const validate = <T, U = boolean | string>( | |
validations: Validation<T, U>[], | |
fields: T | |
): ValidationResult<T, U> => | |
validations | |
.map(validation => validation(fields)) | |
.reduce((acc, a) => Object.assign(acc, a), {}); |
/** | |
* Arbitrary-length tuples | |
* ======================= | |
* | |
* Working with tuples of unknown length in TypeScript is a pain. Most library authors fall back on enumerating all possible | |
* tuple lengths up to a threshold (see an example here https://github.com/pelotom/runtypes/blob/fe19290d375c8818d2c52243ddc2911c8369db37/src/types/tuple.ts ) | |
* | |
* In this gist, I'm attempting to leverage recursion to provide support for arbitrary length tuples. This has the potential | |
* to make some kinds of declarative APIs nicer and enhance type inference in some cases. | |
* This example shows how to take a variable-length tuple as an input, transform each of its types and use the resulting |
export namespace TupleUtils { | |
/** | |
* Get type of first element | |
* @example `First<[0, 1, 2]>` → `0` | |
*/ | |
export type First<Tuple extends [any, ...any[]]> = Tuple[0] | |
/** | |
* Get type of last element |
Angular app talking to multiple microservices using Cookie authentication on ajax requests. Cookies are not passed over cross domain ajax requests, so we need to be able to have the Angular app and microservices running on same-domain in local dev as well as in production.
We have a Docker nginx proxy running on localhost:8000
:
localhost:8000/api/<microservice>
en0 inet (192.168.1.5 for instance)
port 4200
en0
IP and write it to the nginx config at proxy startupconst foo = function <T>(a: T, b: T[]): any { | |
return { a, b } | |
} | |
foo(6, 'di') | |
foo(6, [9]) | |
foo<string>(6, 'di') | |
foo<string>('foo', 'di') | |
foo<string>('foo', ['di']) | |
foo<object>({}, [{}]) |
function handleKill1() { | |
setInterval(createModal, 1000); | |
} |
const open = document.querySelector(".open"); | |
function createModal() { | |
... | |
} | |
open.addEventListener("click", createModal); | |
document.addEventListener("keyup", event => { | |
event.preventDefault(); |