This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Это просто функция, пока еще обычная функция без каких либо дополнительных опций. Единственное надо принять во внимание, | |
//на указатель this который в будущем как бы скажет в коде "используй переменную name из этого класса, а не извне" | |
function Comment( name = 'Default Comment', text = 'default description', url = 'none' ) { | |
this.name = name; | |
this.text = text; | |
this.url = url; | |
this.likes = 0; | |
} | |
//Ты говоришь что прототипом объекта Comment является объект в котором есть конструктор (он равен функции Коммент и есть |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Message { | |
//Важный момент что мы передадим айди, чтобы потом по этому айди можно было достать элемент | |
constructor(title, body, author, id) { | |
this.title = title; | |
this.body = body; | |
this.author = author; | |
this.id = id; | |
} | |
//функция отображения. По сути месседж знает о принадлежащих ему ансерах. И сначала выводиться меседж а потом |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const POSTS = [ | |
{ id:1, | |
name: 'post dog', | |
date: { | |
time: [6, 3, 2018], | |
} | |
}, | |
{ id:12, | |
name: 'post dog', | |
date: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getUniqueObject(nonUniqueArray) { | |
let result = []; | |
for (let i = 0; i < nonUniqueArray.length; i++) { | |
let currentItem = nonUniqueArray[i]; | |
if (isObjectPresent(result, currentItem)) { | |
console.log('object is similar') | |
} else { | |
result.push(currentItem) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Animal(name) { | |
this.name = name | |
} | |
Animal.prototype.getName = function() { | |
return this.name | |
} | |
function Dog(name) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kill all running containers with docker kill $(docker ps -q) | |
delete all stopped containers with docker rm $(docker ps -a -q) | |
delete all images with docker rmi $(docker images -q) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const withStorage = (WrappedComponent) => { | |
class HOC extends React.Component { | |
state = { | |
localStorageAvailable: false, | |
}; | |
componentDidMount() { | |
this.checkLocalStorageExists(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const highOrderComponent = (WrappedComponent) => { | |
class HOC extends React.Component { | |
render() { | |
return <WrappedComponent/>; | |
} | |
} | |
HOC.displayName = `HOC of ${WrappedComponent.displayName || WrappedComponent.name || 'Component'}`; | |
return HOC; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//функция, которая формирует тему | |
const makeStyle = theme => ({ | |
background: theme.mainColor, | |
}) | |
//Сам ХОК | |
const WithStyle = styleParam => (WrappedComponent) => { | |
return class withStyleHOC extends React.Component { | |
render() { | |
const myProps = { someProp: 123 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const trace=label=>value=>{ | |
console.log(`${ label }: ${ value }`); | |
return value; | |
}; | |
const simpleTrace = value => console.log(value); | |
const pipe = (...fns) => (args) => fns.reduce((arg, fn) => fn(arg), args); | |
const compose = (...fns) => (args) => fns.reduce((arg, fn) => fn(arg), args); | |
const mult = a => b => a*b; | |
const add = (a) => (b) => a+b; |
OlderNewer