Skip to content

Instantly share code, notes, and snippets.

View talamaska's full-sized avatar

Zlati Pehlivanov talamaska

View GitHub Profile
@talamaska
talamaska / test-helper.spec.ts
Created August 3, 2017 16:35 — forked from Tuizi/test-helper.spec.ts
MockStore for Angular ngrx/store unit tests
import { Action, ActionReducer, Store } from '@ngrx/store';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operator/map';
import { Observer } from 'rxjs/Observer';
// TODO: How to initialize those variables?
const dispatcherMock: Observer<Action>,
reducerMock: Observer<ActionReducer<any>>,
stateMock: Observable<any>;
@talamaska
talamaska / color-conversion-algorithms.js
Created August 9, 2017 20:39 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@angular-devkit/build-optimizer@~0.0.35":
version "0.0.35"
resolved "https://registry.yarnpkg.com/@angular-devkit/build-optimizer/-/build-optimizer-0.0.35.tgz#3aadad1d7e9ffc7dcd106fda8a5670465936562c"
dependencies:
loader-utils "^1.1.0"
source-map "^0.5.6"
{
"name": "admin",
"version": "1.0.0",
"scripts": {
"ng": "ng",
"yarn": "yarn",
"e2e:client": "ng e2e --app fw-app",
"lint:client": "ng lint --app fw-app",
"test:client": "ng test --app fw-app",
"build:client": "ng build --app fw-app",
// Nothing changed here, works as previously.
@Effect() actionX$ = this.updates$
.ofType('ACTION_X')
.map(toPayload)
.switchMap(payload => this.api.callApiX(payload)
.map(data => ({type: 'ACTION_X_SUCCESS', payload: data}))
.catch(err => Observable.of({type: 'ACTION_X_FAIL', payload: err}))
);
@talamaska
talamaska / conditional_effects.ts
Created February 20, 2018 11:32 — forked from vespertilian/conditional_effects.ts
Two options for conditional ngrx effects
@Effect()
selectAndLoadStore$: Observable<Action> = this.actions$
.ofType(storeActions.SELECT_AND_LOAD_STORE)
.withLatestFrom(this.store.select(ngrx.storeState))
.map(([action, storeState]) => [action.payload, storeState])
.switchMap(([storeName, storeState]) => {
const existsInStore = Boolean(storeState.urlNameMap[storeName]);
return Observable.if(
() => existsInStore,
Observable.of(new storeActions.SetSelectedStore(storeName)),
@talamaska
talamaska / line.effect.ts
Created February 20, 2018 11:33 — forked from vteivans/line.effect.ts
Simple ngrx effect example with `withLatestFrom` operator for blog post: https://medium.com/@viestursv/how-to-get-store-state-in-ngrx-effect-fab9e9c8f087#.oekqp1ucb
import { Store, Action } from '@ngrx/store';
import { Actions, Effect } from '@ngrx/effects';
import { ADD_LINE } from './lines.reducer';
import { INC_PAGE_COUNT } from './pages.reducer';
import { AppState } from './app.store';
@Injectable()
export class LineEffects {
@talamaska
talamaska / recipe.example.md
Created February 20, 2018 11:34 — forked from peterbsmyth/recipe.example.md
Making chained API Calls using @ngrx/Effects

Making chained API Calls using @ngrx/Effects

Purpose

This recipe is useful for cooking up chained API calls as a result of a single action.

Description

In the below example, a single action called POST_REPO is dispatched and it's intention is to create a new repostiory on GitHub then update the README with new data after it is created.
For this to happen there are 4 API calls necessary to the GitHub API:

  1. POST a new repostiry
  2. GET the master branch of the new repository
  3. GET the files on the master branch
@talamaska
talamaska / loading-spinner.service.ts
Created May 15, 2018 13:53 — forked from caroso1222/loading-spinner.service.ts
Angular CDK - Portal and PortalHost
import {
Injectable,
ComponentFactoryResolver,
ApplicationRef,
Injector
} from '@angular/core';
import {
ComponentType,
Portal,
ComponentPortal,
@talamaska
talamaska / form.modal.component.ts
Last active July 23, 2020 13:01
component portal modals
this.isSuccessSub = this.isSuccess$.subscribe((isSuccess) => {
if (isSuccess) {
this.dialogRef.close();
}
});