Skip to content

Instantly share code, notes, and snippets.

View FunnyGhost's full-sized avatar
💭
💻 🐵

Catalin Ciubotaru FunnyGhost

💭
💻 🐵
View GitHub Profile
@FunnyGhost
FunnyGhost / cars.service.ts
Created December 13, 2021 15:45
How to import the LanguageService
@Injectable({
providedIn: 'root'
})
export class CarsService {
const userLanguage: LanguageShortName;
constructor(
private languageService: LanguageService,
) {
this.userLanguage = this.languageService.getLanguage('en');
@FunnyGhost
FunnyGhost / app.server.module.ts
Created December 13, 2021 15:35
Server implementation of the Language Service
@NgModule({
imports: [
// The AppServerModule should import your AppModule followed
// by the ServerModule from @angular/platform-server.
AppModule,
ServerModule,
ServerTransferStateModule,
NoopAnimationsModule
],
providers: [
@FunnyGhost
FunnyGhost / app.module.ts
Created December 13, 2021 15:32
App module overriding Language Service
@NgModule({
imports: [
...
],
declarations: [
...
],
// Providers that are different between the Server and the Browser
providers: [
...
@FunnyGhost
FunnyGhost / server-language.service.ts
Created December 13, 2021 15:27
Server implementation of the Language Service
import { Inject, Injectable } from '@angular/core';
import { LanguageService, LanguageShortName } from 'somewhere';
import { REQUEST } from '@nguniversal/express-engine/tokens';
import { Request } from 'express';
@Injectable()
export class ServerLanguageService extends LanguageService {
constructor(@Inject(REQUEST) private request: Request) {
super();
}
@FunnyGhost
FunnyGhost / web-language.service.ts
Created December 13, 2021 15:21
Browser Language Service
import { Injectable } from '@angular/core';
import { LanguageService, LanguageShortName } from 'somewhere';
@Injectable()
export class WebLanguageService extends LanguageService {
constructor() {
super();
}
getLanguage(defaultLanguage: LanguageShortName): LanguageShortName {
@FunnyGhost
FunnyGhost / language.service.ts
Created December 13, 2021 15:18
Contract for Language Service
import { LanguageShortName } from '../models/language-short-name';
export abstract class LanguageService {
readonly SUPPORTED_LANGUAGES: LanguageShortName[] = ['nl', 'en', 'sv', 'de'];
public abstract getLanguage(defaultLanguage: LanguageShortName): LanguageShortName;
}
@FunnyGhost
FunnyGhost / movie.service.ts
Created July 27, 2021 13:47
MovieService with StatusCodeResponseService
import { Injectable, Optional } from '@angular/core';
import { Observable } from 'rxjs';
import { StatusCodeResponseService } from './status-code-response.service';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { environment } from '@env/environment';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
@FunnyGhost
FunnyGhost / core.module.ts
Created July 27, 2021 13:39
CoreModule with StatusCodeResponseService
import { NgModule } from '@angular/core';
import { StatusCodeResponseService } from './status-code-response.service';
@NgModule({
providers: [StatusCodeResponseService],
})
export class CoreModule {}
@FunnyGhost
FunnyGhost / status-code-response.service.ts
Last active July 27, 2021 13:58
StatusCodeResponseService
import { Inject, Injectable, Optional } from '@angular/core';
import { RESPONSE } from '@nguniversal/express-engine/tokens';
import { Response } from 'express';
@Injectable()
export class StatusCodeResponseService {
private response: Response;
constructor(
@Optional()
@FunnyGhost
FunnyGhost / convert-to-jest.js
Created February 11, 2021 10:19
Convert karma to jest script
// Can be run with a file like this:
// node convert-to-jest.js src/app/home/search/search.component.spec.ts
var fs = require('fs');
var filename = process.argv[2];
if (!filename) {
let specs = require('glob').sync('src/**/*.spec.ts');
for (spec of specs) {
if (!spec.includes('pact')) {