This file contains hidden or 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 { createStore, applyMiddleware } from 'redux' | |
| import reducer from './reducers' | |
| const middlewere = (store) => (dispatch) => (action) => { | |
| if (typeof action === 'string') { | |
| console.log(store.getState()); | |
| return dispatch({ | |
| type: action | |
| }) |
This file contains hidden or 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 enhancer = (createStore) => (...args) => { | |
| const store = createStore(...args); | |
| const orDispatch = store.dispatch; | |
| store.dispatch = (action) => { | |
| if (typeof action === 'string') { | |
| return orDispatch({ | |
| type: action | |
| }) | |
| } else { | |
| return orDispatch(action) |
This file contains hidden or 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 updateCartItems = (cartItems, item, idx) => { | |
| if (item.count === 0) { | |
| return [ | |
| ...cartItems.slice(0,idx), | |
| ...cartItems.slice(idx + 1) | |
| ] | |
| } | |
| if (idx > -1) { | |
| return [ |
This file contains hidden or 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 getResource = async (url) => { | |
| const res = await fetch(url); | |
| if (!res.ok) { | |
| throw new Error(`Could not fetch ${url}`, `received ${res.status}`) | |
| } | |
| const body = await res.json(); | |
| return body; | |
| } | |
This file contains hidden or 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, voice) { | |
| // this.name = name; | |
| // this.voice = voice; | |
| // } | |
| // Animal.prototype.say = function () { | |
| // console.log(`${this.name} says: ${this.voice}`); | |
| // } | |
| // const dog = new Animal('Dog', 'Woof'); | |
| // const cat = new Animal('Cat', 'Myau'); |
This file contains hidden or 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
| try { | |
| // потенциально опасный код | |
| // потенциально опасный код | |
| } catch (error) { | |
| // обработка | |
| // обработка | |
| } | |
| function div(a, b) { | |
| try { |
This file contains hidden or 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
| console.log('Простое сообщение с форматированием %s там там %s', 'первая %s','вторая %s'); | |
| console.error(); | |
| console.info(); | |
| console.warn(); | |
| console.trace(); // путь к вызову этой функции | |
| // Groups | |
| console.group('Имя группы')ж |
This file contains hidden or 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
| // https://codeguida.com/post/756 | |
| fetch('some-url', options); | |
| fetch('some-url') | |
| .then(handleResponse) | |
| .then(data => console.log(data)) | |
| .then(error => console.log(error)) |
This file contains hidden or 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
| 'use strict'; | |
| // TODO Destructurization ДЕСТРУКТУРИЗАЦИЯ | |
| // STUB Syntax Синтаксис: | |
| let {prop : varName = default, ...} = object | |
| // Здесь двоеточие : задаёт отображение свойства prop в переменную varName, а равенство =default задаёт выражение, которое будет использовано, если значение отсутствует (не указано или undefined). | |
| // Для массивов имеет значение порядок, поэтому нельзя использовать :, но значение по умолчанию – можно: | |
| let [var1 = default, var2, ...rest] = array | |
| // ANCHOR Array Destructurization |
This file contains hidden or 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
| location.href = "https://hexlet.io"; | |
| history | |
| $0 // - якшо ввечти в конслоь, можна отримати доступ до вибраного елемента | |
| console.dir //выводит узлы DOM в формате, удобном для интроспекции. | |
| // Создаем текстовый узел | |
| const textNode = document.createTextNode('life is life'); | |
| // ========ВСТАВКА========= | |
| node.prepend(...nodes) // – вставляет nodes в начало node, | |
| node.after(...nodes) // – вставляет nodes после узла node, | |
| node.before(...nodes) // – вставляет nodes перед узлом node, |