Skip to content

Instantly share code, notes, and snippets.

View ganqqwerty's full-sized avatar

Yuri Katkov ganqqwerty

View GitHub Profile
/**
* @param {number} a
* @param {number} b
* @return {number}
*/
function sum(a, b) {
return a+b;
}
import { faBalanceScale } from '@fortawesome/pro-solid-svg-icons';
import { faBan } from '@fortawesome/pro-regular-svg-icons';
export class IconsModule {
constructor(library: FaIconLibrary) {
library.addIcons(
faBalanceScale,
faBan,
//... and the rest of icons)
}
resolveProduct(code: string): Observable<any> {
if (this.cache[code]) {
console.log('Returning cached value!')
return this.cache[code];
}
console.log('Do the request again')
this.cache[code] = this.http.get(this.URL+code+'.json').pipe(
shareReplay(1),
catchError(err => {
<my-product code="7613034626844"></my-product>
<my-product code="7613034626844"></my-product>
<my-product code="7613034626844"></my-product>
@Component({
selector: 'my-app',
template: `<my-product code="7613034626844"></my-product>
<my-product code="7613034626844"></my-product>
<my-product code="7613034626844"></my-product>`,
})
export class AppComponent {
}
@Component({
selector: 'my-product',
template: `
<pre *ngIf="code">
{{(result$|async)|json}}
</pre>
`,
})
export class ProductComponent {
@Input()
npm run i18n && ng build --base-href / --aot --prod --stats-json
export class IconsModule {
constructor(library: FaIconLibrary) {
library.addIconPacks(far);
library.addIconPacks(fas);
library.addIconPacks(fasPro);
}
}
<fa-icon [icon]="['fas', 'coffee']" size="xs"></fa-icon>
export class ProductService {
private readonly URL = 'https://world.openfoodfacts.org/api/v0/product/';
constructor(private http: HttpClient) {
}
cache = {};