Skip to content

Instantly share code, notes, and snippets.

View ivankisyov's full-sized avatar
🤓
Console Logger, Level 4

Ivan Kisyov ivankisyov

🤓
Console Logger, Level 4
View GitHub Profile
@ivankisyov
ivankisyov / gist:bbc1143812011efd766c3e536ba667a5
Created March 20, 2024 13:37
State management: Thought process
1. Identify feature: "Messages"
2. Define state: { messages: Message[], selectedMessage: Message }
3. Define actions: LoadMessages, LoadMessagesSuccess, LoadMessagesError, SelectMessage
4. Define reducers:
function messagesReducer(state, action) {
switch(action.type) {
case LoadMessagesSuccess: return { ...state, messages: action.payload };
case SelectMessage: return { ...state, selectedMessage: action.payload };
default: return state;
}
@ivankisyov
ivankisyov / ngrx-testing-workflow.md
Last active October 11, 2020 20:28
NGRX Testing Principles

NGRX Testing Principles

Testing reducer:

  • pass state and action and expect on the result

Testing selector:

  • use projector method of a selector and pass some stubbed state to it and expect on the result

Testing effects:

@ivankisyov
ivankisyov / app-planning.md
Last active August 18, 2020 21:41
App build with state management in mind

App build with state management in mind

  1. Define the interfaces
  2. Define the overall state
  3. Define the actions
@ivankisyov
ivankisyov / debug.ts
Created August 17, 2019 17:43
RxJs - debug helper operator
import {Observable} from 'rxjs';
import {tap} from 'rxjs/operators';
// original source:
// https://github.com/angular-university/rxjs-course/blob/master/src/app/common/debug.ts
export enum RxJsLoggingLevel {
TRACE,
DEBUG,
INFO,
@ivankisyov
ivankisyov / angular-review-28-07.md
Created July 28, 2019 09:46
angular-review-28-07: testing, forms and a little bit of general info

clean code

  • small functions - 10 lines max
  • proper naming
  • single responsibility

jasmine - test framework

karma - test runner

@ivankisyov
ivankisyov / helpers.md
Last active April 17, 2019 07:01
Helpers

Helpers

A list of helper software that makes my life easier

@ivankisyov
ivankisyov / reacitve-forms.md
Last active April 9, 2019 05:25
[Angular] Reactive forms

[Angular] Reactive forms

Simple reactive form example

export class YourComponent implements OnInit {
  myReactiveForm = new FormGroup({
    username: new FormControl("", Validators.required),
    password: new FormControl("", Validators.required)
  });
@ivankisyov
ivankisyov / rxjs-operators.md
Last active April 8, 2019 04:03
RxJS Operators

RxJS Operators

  • catch - dealing with errors
delete(id) {
  return this.http.delete(this.url + '/' + id)
          .catch(this.handlerError)
}
  • toPromise - use promise instead of observable(the observable is converted to a promise)
@ivankisyov
ivankisyov / errors.md
Last active April 7, 2019 16:34
[Wiki] Errors

Errors

Types of errors

  • unexpected
    • server offline
    • unhandled exceptions
    • network is down
  • expected
    • 400 - Bad Request
  • 404 - Not Found
@ivankisyov
ivankisyov / classesInTS.md
Created April 4, 2019 04:34
[TS] class props and fields
class Point {
    // fields _x, _y
  constructor(private _x: number, private _y: number) {}

  // property x
  get x() {
    console.log(this._x);
    return this._x;
 }