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 logConnections = (pool) => () => { | |
console.log('db_connections_used', pool.numUsed()); | |
console.log(('db_connections_free', pool.numFree()); | |
console.log(('db_connections_pending_creation', pool.numPendingCreates()); | |
console.log(( | |
'db_connections_pending_detroy', | |
pool['pendingDestroys'].length | |
); | |
}; |
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
{ | |
"TerminalKey": "TinkoffTest", | |
"Amount": 101000, | |
"OrderId": "131", | |
"Shops": [ | |
{ | |
"ShopCode": "111", | |
"Amount": "100207", | |
"Name": "Установка ванной", | |
"Fee":"207" |
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
updateState({target}) { | |
this.setState((prevState) => { | |
const updatedUser = {…prevState.user, [target.name]: target.value}; | |
// используем предыдущее значение в state для создания нового state… | |
return { user: updatedUser }; | |
// И то что вернется будет назначено как новое состояние state | |
}, () => this.doSomething(this.state.user); | |
// Теперь я могу спокойно использовать новое состояние state | |
//для обработки в другой функции… | |
); |
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
updateState({target}) { | |
this.setState({user: {…this.state.user, [target.name]: target.value}}); | |
doSomething(this.state.user) | |
// упс, setState просто запланировал изменение состояния, | |
//так что this.state.user может вернуть еще старое значение | |
} |
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 { Map } from 'immutable'; | |
// Затем в конструкторе... | |
this.state = { | |
// создаем неизменяемый map в состоянии state с помощью immutable.js | |
user: Map({ firstName: 'Cory', lastName: 'House'}) | |
}; | |
updateState({target}) { |
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 update from 'immutability-helper'; | |
updateState({target}) { | |
let user = update(this.state.user, {$merge: {[target.name]: target.value}}); | |
this.setState({user}); | |
} |
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
updateState({target}) { | |
this.setState({user: {...this.state.user, [target.name]: target.value}}); | |
} |
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
updateState(event) { | |
const {name, value} = event.target; | |
let user = {...this.state.user, [name]: value}; | |
this.setState({user}); | |
} |
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
updateState(event) { | |
const {name, value} = event.target; | |
let user = Object.assign({}, this.state.user); | |
user[name] = value; | |
return this.setState({user}); | |
} |
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
updateState(event) { | |
const {name, value} = event.target; | |
let user = this.state.user; // это ссылка, не копия... | |
user[name] = value; // так что меняем состояние? | |
return this.setState({user}); | |
} |
NewerOlder