Skip to content

Commit

Permalink
got rid of .bind() and ran build for production
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwestbury committed Dec 5, 2017
1 parent 553210f commit 1956830
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 45 deletions.
31 changes: 12 additions & 19 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ class App extends React.Component {
constructor() {
super();

this.addFish = this.addFish.bind(this);
this.loadSamples = this.loadSamples.bind(this);
this.addToOrder = this.addToOrder.bind(this);
this.updateFish = this.updateFish.bind(this);
this.removeFish = this.removeFish.bind(this);
this.removeFromOrder = this.removeFromOrder.bind(this);

this.state = {
fishes: {},
order: {}
Expand Down Expand Up @@ -50,42 +43,42 @@ class App extends React.Component {
}


addFish(fish) {
addFish = (fish) => {
const fishes = {...this.state.fishes};
const timestamp = Date.now();
fishes[`fish-${timestamp}`] = fish;
this.setState({ fishes })
}
};

updateFish (key, updatedFish) {
updateFish = (key, updatedFish) => {
const fishes = {...this.state.fishes};
fishes[key] = updatedFish;
this.setState({ fishes });
}
};

removeFish(key) {
removeFish = (key) => {
const fishes = {...this.state.fishes};
fishes[key] = null;
this.setState({ fishes });
}
};

loadSamples() {
loadSamples = () => {
this.setState({
fishes: sampleFishes
});
}
};

addToOrder(key) {
addToOrder = (key) => {
const order = {...this.state.order};
order[key] = order[key] + 1 || 1;
this.setState({ order });
}
};

removeFromOrder(key) {
removeFromOrder = (key) => {
const order = {...this.state.order};
delete order[key];
this.setState({ order });
}
};

render() {
return (
Expand Down
32 changes: 13 additions & 19 deletions src/components/Inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import base from '../base';
class Inventory extends React.Component {
constructor () {
super();
this.renderInventory = this.renderInventory.bind(this);
this.handleChange = this.handleChange.bind(this);
this.renderLogin = this.renderLogin.bind(this);
this.logout = this.logout.bind(this);
this.authenticate = this.authenticate.bind(this);
this.authHandler = this.authHandler.bind(this);

this.state = {
uid: null,
owner: null
Expand All @@ -26,31 +21,31 @@ class Inventory extends React.Component {
});
}

handleChange(e, key) {
handleChange = (e, key) => {
const fish = this.props.fishes[key];
const updatedFish = {
...fish,
[e.target.name]: e.target.value
}
this.props.updateFish(key, updatedFish);
}
};

authenticate(provider) {
authenticate = (provider) => {
console.log(`Trying to log in with ${provider}`);
base.authWithOAuthPopup(provider, this.authHandler);
}
};

logout() {
logout = () => {
base.unauth();
this.setState({ uid: null });
}
};

authHandler(err, authData) {
authHandler = (err, authData) => {
console.log(authData);
if(err) {
console.error(err);
return;
}
};

//grab store info
const storeRef = base.database().ref(this.props.storeId);
Expand All @@ -59,7 +54,6 @@ class Inventory extends React.Component {
storeRef.once('value', (snapshot) => {
const data = snapshot.val() || {};


//claim it as our own if there is no owner already
if(!data.owner) {
storeRef.set({
Expand All @@ -74,7 +68,7 @@ class Inventory extends React.Component {
});
}

renderLogin() {
renderLogin = () => {
return (
<nav className='login'>
<h2>Inventory</h2>
Expand All @@ -84,10 +78,10 @@ class Inventory extends React.Component {
<button className='twitter' onClick={() => this.authenticate('twitter')}>Log in with Twitter</button>
</nav>
)
}
};


renderInventory(key) {
renderInventory = (key) => {
const fish = this.props.fishes[key];
return (
<div className='fish-edit' key={key}>
Expand All @@ -102,7 +96,7 @@ class Inventory extends React.Component {
<button onClick={() => this.props.removeFish(key)}>Remove Fish</button>
</div>
)
}
};

render() {
const logout = <button onClick={this.logout}>Log Out!</button>
Expand Down
1 change: 0 additions & 1 deletion src/components/NotFound.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ const NotFound = ({location}) => (
</div>
)


export default NotFound;
9 changes: 3 additions & 6 deletions src/components/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import PropTypes from 'prop-types';


class Order extends React.Component {
constructor () {
super();
this.renderOrder = this.renderOrder.bind(this);
}
renderOrder(key) {

renderOrder = (key) => {
const fish = this.props.fishes[key];
const count = this.props.order[key];
const removeButton = <button onClick={() => this.props.removeFromOrder(key)}>&times;</button>

if(!fish || fish.status === 'unavailable') {
return <li key={key}> Sorry, {fish ? fish.name : 'fish'} is no longer available! {removeButton}</li>
}
};

return (
<li key={key}>
Expand Down

0 comments on commit 1956830

Please sign in to comment.