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
let updatedPassengers = this.state.passengers; | |
updatedPassengers.push('Mitchell, Vincent M.'); | |
this.setState({passengers:updatedPassengers}); |
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
// updatedPassengers is a new array, returned from concat | |
let updatedPassengers = this.state.passengers.concat('Mitchell, Vincent M.'); | |
this.setState({passengers:updatedPassengers}); |
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
// updatedTicket is a new object with the original properties of this.state.ticket | |
// merged with the new flightNo. | |
var updatedTicket = Object.assign({}, this.state.ticket, {flightNo:'1010'}); | |
this.setState({ticket:updatedTicket}); |
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
let originalTicket = { | |
company: 'Dalta', | |
flightNo: '0990', | |
departure: { | |
airport: 'LAS', | |
time: '2016-08-21T10:00:00.000Z' | |
}, | |
arrival: { | |
airport: 'MIA', | |
time: '2016-08-21T14:41:10.000Z' |
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
newTicket.arrival.airport='MCO' |
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
let student = {name:'John Caster', grades:['A','C','B']} |
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
let newStudent = React.addons.update(student, {grades:{$push: ['A']}}) |
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
let newStudent = update(student, {grades:{$set: ['A','A','B']}}) |
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
let newTicket = update(originalTicket, { | |
arrival: { | |
airport: {$set: 'MCO'} | |
} | |
}); |