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
class ItemList extends Component { ... }; | |
const widthData = (View) => { | |
return class extends Component { | |
componentDidMount() { | |
console.log(this.props); // children: item => {…} ,getData: async () => {…}, onItemListClicked: id => {…}, pageId: 1 | |
} | |
render() { | |
return <ItemList {...this.props} />; | |
} |
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
// 1. Скопировать объект - Object.assign | |
Object.assign({}, event); | |
// 2. Скопировать и добавить свойство в объект (копию объекта - не мутация) - Object.assign | |
Object.assign({}, event, {id: localNewEventId}); | |
// или | |
Object.assign( | |
{}, | |
event, // старый объект |
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
// 1 Вывести продолжительность поездки | |
// В колонке «Time» отображается время и продолжительность нахождения в точке маршрута (разность между окончанием и началом события). Время маршрута отображается в формате начало — окончание (например, «10:30 — 11:00»). Формат продолжительности нахождения в точке маршрута зависит от длительности: | |
// Менее часа: минуты (например «23M»); | |
// Менее суток: часы минуты (например «02H 44M»); | |
// Более суток: дни часы минуты (например «01D 02H 30M»); | |
const getDurationDiff = (countTime, label) => { | |
return countTime ? countTime + label : ``; | |
}; |
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
// обновление | |
[ ...this._events.slice(0, index), | |
update, | |
...this._events.slice(index + 1) | |
]; | |
// добавление | |
[ | |
update, |
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
// Сумма элементов массива | |
ar.reduce((a, b) => (a + b)) |
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
// Чтобы можно было работать с массивом через foreach, нужно отрезать кусочек через функцию slice(0, countElArr) | |
var pinsCount = Math.min(offers.length, MAX_PINS_COUNT); | |
offers.slice(0, pinsCount).forEach(function (item, i) { | |
//... | |
}); |
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
// было | |
this.SwapiService.getPost(postId) // Функция Меняется | |
// стало | |
getData(postId) |
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
// app.js - вызов компонента | |
<ErrorBoundry> | |
<Row left={postsList} right={postItem}></Row> | |
</ErrorBoundry> | |
// app.js - создадим компонент класс | |
class ErrorBoundry extends Component { | |
state = { | |
hasError: false, | |
}; |
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
// app.js | |
<Posts> | |
{(item) =>// Это и есть свойство потомок | |
`${item.title} <span class="date">(${item.date})</span>` | |
} | |
</Posts> | |
// post.js | |
const label = this.props.children(item); // Вытащим данное свойство |
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
// изночально было так ... | |
render(){ | |
<Posts renderItem={({ title, date }) => `${title} <span class="date">(${date})</span>`}/> | |
} | |
// перевод в переменную | |
render(){ | |
const postsList = ( | |
<Posts renderItem={({ title, date }) => `${title} <span class="date">(${date})</span>`}/> | |
); |