1/1/19

What is decorator

After a lot of time working with angular, I suddenly found myself wondering: What exactly this syntax (like here):

@Component({
  selector: 'kinder-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent {
  showFeddback = false;
}
(which I use so lot of times) means?
In other words: what is exactly decorator?
According to angularjs docs:
Decorators are a design pattern that is used to separate modification or decoration of a class without modifying the original source code Which means: after you create some class - the decorator adds some additional functionality to it.
I decided to to experiment with creating my own decorator (to see how it feels to write decorator):


import { Component } from '@angular/core';
export function Vasia() {  
     console.log(`hhh!!!!`)   
}
@Vasia()
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Beautifull Girl';
}
Now each time you refresh the page - you will see 'stay with me!!!!' output in the console

12/30/18

Is it complicate to write unit tests for your React app?

Not at all!
All you need is to install jest testing framework:

npm add --D jest babel-jest babel-preset-env babel-preset-react react-test-renderer
Add "test" script to "scripts" section in package.json file

  "scripts": {
    "start": "webpack-dev-server --open",
    "test": "jest",
Now you have the testing environment configured and running.
And you can start with adding some very simple unit test
You can create it on some file which has ".test" in its name - like example.test.js

test('adds 1 + 2 to equal 3', () => {
  expect(1 + 2).toBe(3);
});
After running
npm test
the result will be something like this
Now nobody can say about you that you never wrote a single test

12/11/18

Distructuring cheatsheet

Since I keep find myself forgot the ES6 destructuring syntax again and again I decided to publish this cheatsheet:

If you want to print one property of object:


const object = {name:'vasia'};
const {name} = object; 
console.log(`${name}`); // vasia 


If you want to this property to be named differently (bio)


const object = {name:'vasia'};
const {name: bio} = object; 

console.log(`${bio}`); // vasia 


If this property is inside other property (person)


const object ={person: {name:'vasia'}};
const {person:{name}} = object;

console.log(`${name}`); // vasia 
Hope this post will make me remember...

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...