This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!document.referrer.includes(window.location.host)) { | |
this.analyticsSink.logFirstLoadEvent(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ExampleInterface { | |
exampleMethod(result: string): void; | |
} | |
export class CorrectExampleClass implements ExampleInterface { | |
exampleMethod(result: string) { | |
console.log('This is okay :D'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Similar magic I want to achieve: | |
type Role = 'patient' | 'clinician' | 'admin'; | |
// No need to declare one by one! | |
type capitalizedRole = Capitalize<Role>; | |
// The example goes as follows: | |
interface GenericEvent { | |
id: string; | |
view: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new array of length X, that contains the index 1 to the length. | |
const x = 10; | |
const numbers = new Array(x).fill(null).map((_,i)=> i 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HostListener('document:visibilitychange', ['$event']) | |
visibilitychange() { | |
if (document.visibilityState === 'hidden') { | |
console.log('hidden'); | |
} else { | |
console.log('visible'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* When returning false, it provokes the browser to show the popup asking if they want to leave without saving. */ | |
@HostListener('window:beforeunload', ['$event']) | |
beforeUnloadHander(event) { | |
console.log('window:beforeunload'); | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This method detects when the user is leaving without prompting anything. */ | |
@HostListener('window:unload', ['$event']) | |
unloadHandler(event) { | |
console.log('window:unload'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if an object is has all the properties defined. | |
* | |
* Attention: It does not work recursively. | |
* @param obj Object to scan. | |
* @param type Object type. | |
* @returns Boolean, depending on if all the properties are defined or not. | |
*/ | |
defined<T>(obj: T, type: new () => T): boolean { | |
if (!obj) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Compares two same type objects to check if their properties and values are equals. | |
* | |
* Attention: It is not recursively. | |
* @param original Original element to have as a base. | |
* @param compareTo element to compare to with the original one. | |
* @returns The result from comparing both. | |
*/ | |
equals<T>(original: T, compareTo: T): boolean { | |
if (!original && !compareTo) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Duplica el contenido de un objeto sobre otro del mismo tipo. | |
* | |
* @param source Objeto a partir de cual obtener los valores | |
* @param destiny Objeto al cual asignar dichos valores | |
*/ | |
mapAll<T>(source: T, destiny: T) { | |
const keys: any[] = Object.keys(source); | |
keys.forEach((key) => { |
NewerOlder