-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal: Todos demo setup and scaffolding (#3)
* Restructure and rehash todo demo * Finish scaffolding for demo
- Loading branch information
Showing
34 changed files
with
372 additions
and
141 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
!**/*.tsx | ||
|
||
# Unless they're somewhere we can ignore | ||
build/ | ||
dist/ | ||
coverage/ | ||
node_modules/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
## Todo List demo | ||
|
||
This project takes the ["Todo List" example from Redux](https://redux.js.org/basics/example) and wraps the Redux state | ||
in `atomFromReduxState` so that it can be interacted with via Recoil. | ||
This demo project takes the ["Todo List" example from Redux](https://redux.js.org/basics/example) and uses | ||
[Redux-to-Recoil](https://github.com/spautz/redux-to-recoil) to access the Redux state via Recoil. | ||
|
||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
There are three different implementations of the UI, running side-by-side: | ||
|
||
[See the original readme here](./create-react-app.md). | ||
- The original plain Redux version: read from Redux state, dispatch actions to Redux | ||
- A Recoil state version: read from Recoil state, dispatch actions to Redux | ||
- A bidirectional Recoil state version: read from Recoil state, write to Recoil state | ||
|
||
This project was bootstrapped with [Create React ReduxApp](https://github.com/facebook/create-react-app). |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
|
||
const ReduxApp = () => ( | ||
<fieldset> | ||
<legend>Bidirectional Redux-to-Recoil</legend> | ||
TODO | ||
</fieldset> | ||
); | ||
|
||
export default ReduxApp; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
|
||
import { VisibilityFilters } from './actions'; | ||
import AddTodo from './components.recoil/AddTodo'; | ||
import FilterLink from './components.recoil/FilterLink'; | ||
import VisibleTodoList from './components.recoil/VisibleTodoList'; | ||
|
||
const ReduxApp = () => ( | ||
<fieldset> | ||
<legend> | ||
<legend>Redux-to-Recoil</legend> | ||
</legend> | ||
<AddTodo /> | ||
<VisibleTodoList /> | ||
|
||
<div> | ||
<span>Show: </span> | ||
<FilterLink filter={VisibilityFilters.SHOW_ALL}>All</FilterLink> | ||
<FilterLink filter={VisibilityFilters.SHOW_ACTIVE}>Active</FilterLink> | ||
<FilterLink filter={VisibilityFilters.SHOW_COMPLETED}>Completed</FilterLink> | ||
</div> | ||
</fieldset> | ||
); | ||
|
||
export default ReduxApp; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Because AddTodo doesn't read from the store, it's the same between Redux and Redux-to-Recoil | ||
export { default } from '../components.redux/AddTodo'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { setVisibilityFilter } from '../actions'; | ||
|
||
const FilterLink = (props) => { | ||
const { children, active, onClick } = props; | ||
|
||
return ( | ||
<button | ||
onClick={onClick} | ||
disabled={active} | ||
style={{ | ||
marginLeft: '4px', | ||
}} | ||
> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state, ownProps) => ({ | ||
active: ownProps.filter === state.visibilityFilter, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch, ownProps) => ({ | ||
onClick: () => dispatch(setVisibilityFilter(ownProps.filter)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(FilterLink); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Because Todo doesn't read from the store, it's the same between Redux and Redux-to-Recoil | ||
export { default } from '../components.redux/Todo'; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { setVisibilityFilter } from '../actions'; | ||
|
||
const FilterLink = (props) => { | ||
const { children, active, onClick } = props; | ||
|
||
return ( | ||
<button | ||
onClick={onClick} | ||
disabled={active} | ||
style={{ | ||
marginLeft: '4px', | ||
}} | ||
> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state, ownProps) => ({ | ||
active: ownProps.filter === state.visibilityFilter, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch, ownProps) => ({ | ||
onClick: () => dispatch(setVisibilityFilter(ownProps.filter)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(FilterLink); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
import { toggleTodo } from '../actions'; | ||
import getVisibleTodos from '../selectors/getVisibleTodos'; | ||
import Todo from './Todo'; | ||
|
||
const VisibleTodoList = (props) => { | ||
const dispatch = useDispatch(); | ||
|
||
const todos = useSelector(getVisibleTodos); | ||
|
||
return ( | ||
<ul> | ||
{todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} onClick={() => dispatch(toggleTodo(todo.id))} /> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default VisibleTodoList; |
Oops, something went wrong.