Skip to content

Commit

Permalink
Update React Router example for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
BinaryMuse committed May 19, 2015
1 parent f949b38 commit 487250e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
13 changes: 9 additions & 4 deletions examples/react-router/app/components/recipe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var RecipeStore = require("../stores/recipe_store.jsx");
class Recipe extends React.Component {
constructor() {
super();
this.onDeleteRecipe = this.onDeleteRecipe.bind(this);
this.deleteRecipe = this.deleteRecipe.bind(this);
}

render() {
Expand All @@ -31,7 +31,7 @@ class Recipe extends React.Component {

<p>
<Link to="edit-recipe" params={{id: recipe.id}}>Edit Recipe</Link>
{" | "}<Link to="home" onClick={this.onDeleteRecipe}>Delete Recipe</Link>
{" | "}<Link to="home" onClick={this.deleteRecipe}>Delete Recipe</Link>
</p>
</div>
);
Expand Down Expand Up @@ -62,15 +62,20 @@ class Recipe extends React.Component {
);
}

onDeleteRecipe(e) {
deleteRecipe(e) {
if (confirm("Really delete this recipe?")) {
this.props.deleteRecipe(this.props.recipe.id);
this.props.onDeleteRecipe(this.props.recipe.id);
} else {
e.preventDefault();
}
}
}

Recipe.propTypes = {
recipe: React.PropTypes.object.isRequired,
onDeleteRecipe: React.PropTypes.func.isRequired
};

Recipe.contextTypes = {
router: React.PropTypes.func
};
Expand Down
14 changes: 3 additions & 11 deletions examples/react-router/app/components/recipe_adder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var Recipe = require("../schemas/recipe.jsx"),
RecipeForm = require("../forms/recipe_form.jsx");

class RecipeAdder extends React.Component {
constructor() {
super();
constructor(props) {
super(props);
this.onSubmit = this.onSubmit.bind(this);
}

Expand Down Expand Up @@ -48,18 +48,10 @@ class RecipeAdder extends React.Component {
);
}
}

deleteRecipe(e) {
if (confirm("Really delete this recipe?")) {
this.props.onDeleteRecipe(this.state.recipe.id);
} else {
e.preventDefault();
}
}
};

RecipeAdder.propTypes = {
onAddRecipe: React.PropTypes.func
onAddRecipe: React.PropTypes.func.isRequired
};

RecipeAdder.contextTypes = {
Expand Down
6 changes: 6 additions & 0 deletions examples/react-router/app/components/recipe_editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class RecipeEditor extends React.Component {
}
};

RecipeEditor.propTypes = {
recipe: React.PropTypes.object.isRequired,
onEditRecipe: React.PropTypes.func.isRequired,
onDeleteRecipe: React.PropTypes.func.isRequired
};

RecipeEditor.contextTypes = {
router: React.PropTypes.func
};
Expand Down
4 changes: 4 additions & 0 deletions examples/react-router/app/components/recipe_list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class RecipeList extends React.Component {
</li>
);
}
}

RecipeList.propTypes = {
recipes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
};

module.exports = RecipeList;
3 changes: 1 addition & 2 deletions examples/react-router/app/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ RecipeAdderWrapped = wrap(RecipeAdder, [], (flux) => {
// This example shows how you could provide extra context to
// the props function (in this case, we want access to the router.
RecipeWrapped = wrap(Recipe, ["recipe"], (flux, props, extraContext) => {
console.log(flux.actions);
var params = extraContext.router.getCurrentParams();

return {
recipe: flux.store("recipe").getRecipe(params.id),
deleteRecipe: (recipeId) => {
onDeleteRecipe: (recipeId) => {
flux.actions.recipes.remove(recipeId);
}
};
Expand Down

0 comments on commit 487250e

Please sign in to comment.