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 CompleteOrder | |
def perform | |
notify_recipient(order.recipient) | |
update_inventory(order.item_number) | |
prepare_shippping(order.shipping_address) | |
end | |
private | |
def order |
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 User extends React.PureComponent { | |
// ... | |
updateUserStatus(status) { | |
const { user } = this.state | |
this.state.user.status = status | |
} | |
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 User extends React.Component { | |
// ... | |
updateUserStatus(status) { | |
const { user } = this.state; | |
setState({ user: {...user, status: status }}) | |
} | |
appendItem(newItem) { |
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 shallowEqual from 'shared/shallowEqual'; | |
/* | |
shallowEqual is a helper function from the React source code: | |
https://github.com/facebook/react/blob/72434a7686035b4af766ee7d06c070d7f5d6a5f2/packages/shared/shallowEqual.js | |
*/ | |
shouldComponentUpdate(nextProps, nextState) { | |
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.State, nextState); | |
} |
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 PropTypes from 'prop-types'; | |
Widget.propTypes = { | |
extraArray: PropTypes.array.isRequired, | |
userNames: PropTyes.arrayOf(PropTypes.string).isRequired, | |
userPosts: PropTypes.arrayOf(PropTypes.shape({ | |
id: PropTypes.number.isRequired, | |
title: PropTypes.string.isRequired, | |
body: PropTypes.string.isRequired, | |
postDate: PropTypes.instanceOf(Date).isRequired |
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 PropTypes from 'prop-types'; | |
Widget.propTypes = { | |
// Specify that prop is an object | |
extraData: PropTypes.object.isRequired, | |
// Specify that prop is an object with certain keys | |
userData: PropTypes.shape({ | |
name: PropTypes.string, | |
age: PropTypes.number |
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 PropTypes from 'prop-types' | |
Widget.propTypes = { | |
headerText: PropTypes.string.isRequired, | |
widgetCount: PropTypes.number.isRequired, | |
isFetchingData: PropTypes.bool.isRequired, | |
handlerFunction: PropTypes.func.isRequired, | |
createdAt: PropTypes.instanceOf(Date).isRequired, | |
optionalText: PropTypes.string | |
} |
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 PropTypes from 'prop-types'; | |
class ItemComponent extends React.Component { | |
// propTypes can be defined inside the Component definition | |
static propTypes = { | |
name: PropTypes.string.isRequired, | |
price: PropTypes.number.isRequired, | |
purchaseHandler: PropTypes.func.isRequired | |
}; |
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 PropTypes from 'prop-types'; | |
const ItemDiv = ({ name, price, purchaseHandler }) => { | |
return( | |
<div> | |
div> Item:{name} </div> | |
div> Price:${price} </div> | |
<button onClick={purchaseHandler}> Purchase </button> | |
</div> | |
) |
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 ControlledComponent extends React.Component { | |
constructor( props) { | |
super(props) | |
this.handleSubmit = this.handleSubmit.bind(this) | |
} | |
handleSubmit(event) { | |
event.preventDefault() | |
this.props.createAccount( |