Skip to content

Commit

Permalink
Prettier to basics folder (reduxjs#2386)
Browse files Browse the repository at this point in the history
* Apply prettier to 'basics' folder

* Remove an unnecessary semicolon

* Fix broken indent

* Improve formatting

* Improve formatting

* Revert to a multi-line statement

* Revert to a multi-line statement
  • Loading branch information
CodinCat authored and timdorr committed May 12, 2017
1 parent 35e7394 commit b5db43d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 85 deletions.
4 changes: 2 additions & 2 deletions docs/basics/Actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ dispatch(completeTodo(index))
Alternatively, you can create a **bound action creator** that automatically dispatches:

```js
const boundAddTodo = (text) => dispatch(addTodo(text))
const boundCompleteTodo = (index) => dispatch(completeTodo(index))
const boundAddTodo = text => dispatch(addTodo(text))
const boundCompleteTodo = index => dispatch(completeTodo(index))
```

Now you'll be able to call them directly:
Expand Down
2 changes: 1 addition & 1 deletion docs/basics/DataFlow.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The data lifecycle in any Redux app follows these 4 steps:
// The current application state (list of todos and chosen filter)
let previousState = {
visibleTodoFilter: 'SHOW_ALL',
todos: [
todos: [
{
text: 'Read the docs.',
complete: false
Expand Down
83 changes: 43 additions & 40 deletions docs/basics/ExampleTodoList.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ render(

```js
let nextTodoId = 0
export const addTodo = (text) => {
export const addTodo = text => {
return {
type: 'ADD_TODO',
id: nextTodoId++,
text
}
}

export const setVisibilityFilter = (filter) => {
export const setVisibilityFilter = filter => {
return {
type: 'SET_VISIBILITY_FILTER',
filter
}
}

export const toggleTodo = (id) => {
export const toggleTodo = id => {
return {
type: 'TOGGLE_TODO',
id
Expand Down Expand Up @@ -74,7 +74,7 @@ const todo = (state = {}, action) => {
return Object.assign({}, state, {
completed: !state.completed
})

default:
return state
}
Expand All @@ -84,7 +84,7 @@ const todos = (state = [], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
...state,
todo(undefined, action)
]
case 'TOGGLE_TODO':
Expand Down Expand Up @@ -134,7 +134,7 @@ export default todoApp
#### `components/Todo.js`

```js
import React, from 'react'
import React from 'react'
import PropTypes from 'prop-types'

const Todo = ({ onClick, completed, text }) => (
Expand Down Expand Up @@ -166,22 +166,20 @@ import Todo from './Todo'

const TodoList = ({ todos, onTodoClick }) => (
<ul>
{todos.map(todo =>
<Todo
key={todo.id}
{...todo}
onClick={() => onTodoClick(todo.id)}
/>
)}
{todos.map(todo => (
<Todo key={todo.id} {...todo} onClick={() => onTodoClick(todo.id)} />
))}
</ul>
)

TodoList.propTypes = {
todos: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
completed: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired
}).isRequired).isRequired,
todos: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
completed: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired
}).isRequired
).isRequired,
onTodoClick: PropTypes.func.isRequired
}

Expand All @@ -199,11 +197,12 @@ const Link = ({ active, children, onClick }) => {
}

return (
<a href="#"
onClick={e => {
e.preventDefault()
onClick()
}}
<a
href="#"
onClick={e => {
e.preventDefault()
onClick()
}}
>
{children}
</a>
Expand All @@ -228,15 +227,15 @@ import FilterLink from '../containers/FilterLink'
const Footer = () => (
<p>
Show:
{" "}
{' '}
<FilterLink filter="SHOW_ALL">
All
</FilterLink>
{", "}
{', '}
<FilterLink filter="SHOW_ACTIVE">
Active
</FilterLink>
{", "}
{', '}
<FilterLink filter="SHOW_COMPLETED">
Completed
</FilterLink>
Expand Down Expand Up @@ -285,15 +284,15 @@ const getVisibleTodos = (todos, filter) => {
}
}

const mapStateToProps = (state) => {
const mapStateToProps = state => {
return {
todos: getVisibleTodos(state.todos, state.visibilityFilter)
}
}

const mapDispatchToProps = (dispatch) => {
const mapDispatchToProps = dispatch => {
return {
onTodoClick: (id) => {
onTodoClick: id => {
dispatch(toggleTodo(id))
}
}
Expand Down Expand Up @@ -350,17 +349,21 @@ let AddTodo = ({ dispatch }) => {

return (
<div>
<form onSubmit={e => {
e.preventDefault()
if (!input.value.trim()) {
return
}
dispatch(addTodo(input.value))
input.value = ''
}}>
<input ref={node => {
input = node
}} />
<form
onSubmit={e => {
e.preventDefault()
if (!input.value.trim()) {
return
}
dispatch(addTodo(input.value))
input.value = ''
}}
>
<input
ref={node => {
input = node
}}
/>
<button type="submit">
Add Todo
</button>
Expand Down
13 changes: 9 additions & 4 deletions docs/basics/Reducers.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function todoApp(state = initialState, action) {
completed: false
}
]
})
})
default:
return state
}
Expand Down Expand Up @@ -188,7 +188,7 @@ function todoApp(state = initialState, action) {
case TOGGLE_TODO:
return Object.assign({}, state, {
todos: state.todos.map((todo, index) => {
if(index === action.index) {
if (index === action.index) {
return Object.assign({}, todo, {
completed: !todo.completed
})
Expand Down Expand Up @@ -252,7 +252,7 @@ Let's explore reducer composition more. Can we also extract a reducer managing j

Below our imports, let's use [ES6 Object Destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) to declare `SHOW_ALL`:
```js
const { SHOW_ALL } = VisibilityFilters;
const { SHOW_ALL } = VisibilityFilters
```

Then:
Expand Down Expand Up @@ -380,7 +380,12 @@ All [`combineReducers()`](../api/combineReducers.md) does is generate a function
```js
import { combineReducers } from 'redux'
import { ADD_TODO, TOGGLE_TODO, SET_VISIBILITY_FILTER, VisibilityFilters } from './actions'
import {
ADD_TODO,
TOGGLE_TODO,
SET_VISIBILITY_FILTER,
VisibilityFilters
} from './actions'
const { SHOW_ALL } = VisibilityFilters
function visibilityFilter(state = SHOW_ALL, action) {
Expand Down
7 changes: 6 additions & 1 deletion docs/basics/Store.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ let store = createStore(todoApp, window.STATE_FROM_SERVER)
Now that we have created a store, let's verify our program works! Even without any UI, we can already test the update logic.

```js
import { addTodo, toggleTodo, setVisibilityFilter, VisibilityFilters } from './actions'
import {
addTodo,
toggleTodo,
setVisibilityFilter,
VisibilityFilters
} from './actions'

// Log the initial state
console.log(store.getState())
Expand Down
77 changes: 40 additions & 37 deletions docs/basics/UsageWithReact.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,20 @@ import Todo from './Todo'

const TodoList = ({ todos, onTodoClick }) => (
<ul>
{todos.map(todo =>
<Todo
key={todo.id}
{...todo}
onClick={() => onTodoClick(todo.id)}
/>
)}
{todos.map(todo => (
<Todo key={todo.id} {...todo} onClick={() => onTodoClick(todo.id)} />
))}
</ul>
)

TodoList.propTypes = {
todos: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
completed: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired
}).isRequired).isRequired,
todos: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
completed: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired
}).isRequired
).isRequired,
onTodoClick: PropTypes.func.isRequired
}

Expand All @@ -180,11 +178,12 @@ const Link = ({ active, children, onClick }) => {
}

return (
<a href="#"
onClick={e => {
e.preventDefault()
onClick()
}}
<a
href="#"
onClick={e => {
e.preventDefault()
onClick()
}}
>
{children}
</a>
Expand All @@ -209,15 +208,15 @@ import FilterLink from '../containers/FilterLink'
const Footer = () => (
<p>
Show:
{" "}
{' '}
<FilterLink filter="SHOW_ALL">
All
</FilterLink>
{", "}
{', '}
<FilterLink filter="SHOW_ACTIVE">
Active
</FilterLink>
{", "}
{', '}
<FilterLink filter="SHOW_COMPLETED">
Completed
</FilterLink>
Expand Down Expand Up @@ -264,7 +263,7 @@ const getVisibleTodos = (todos, filter) => {
}
}

const mapStateToProps = (state) => {
const mapStateToProps = state => {
return {
todos: getVisibleTodos(state.todos, state.visibilityFilter)
}
Expand All @@ -274,9 +273,9 @@ const mapStateToProps = (state) => {
In addition to reading the state, container components can dispatch actions. In a similar fashion, you can define a function called `mapDispatchToProps()` that receives the [`dispatch()`](../api/Store.md#dispatch) method and returns callback props that you want to inject into the presentational component. For example, we want the `VisibleTodoList` to inject a prop called `onTodoClick` into the `TodoList` component, and we want `onTodoClick` to dispatch a `TOGGLE_TODO` action:

```js
const mapDispatchToProps = (dispatch) => {
const mapDispatchToProps = dispatch => {
return {
onTodoClick: (id) => {
onTodoClick: id => {
dispatch(toggleTodo(id))
}
}
Expand Down Expand Up @@ -347,15 +346,15 @@ const getVisibleTodos = (todos, filter) => {
}
}

const mapStateToProps = (state) => {
const mapStateToProps = state => {
return {
todos: getVisibleTodos(state.todos, state.visibilityFilter)
}
}

const mapDispatchToProps = (dispatch) => {
const mapDispatchToProps = dispatch => {
return {
onTodoClick: (id) => {
onTodoClick: id => {
dispatch(toggleTodo(id))
}
}
Expand Down Expand Up @@ -383,17 +382,21 @@ let AddTodo = ({ dispatch }) => {

return (
<div>
<form onSubmit={e => {
e.preventDefault()
if (!input.value.trim()) {
return
}
dispatch(addTodo(input.value))
input.value = ''
}}>
<input ref={node => {
input = node
}} />
<form
onSubmit={e => {
e.preventDefault()
if (!input.value.trim()) {
return
}
dispatch(addTodo(input.value))
input.value = ''
}}
>
<input
ref={node => {
input = node
}}
/>
<button type="submit">
Add Todo
</button>
Expand Down

0 comments on commit b5db43d

Please sign in to comment.