Created
May 16, 2017 13:28
-
-
Save aGuyNamedJonas/f12e06aed26bf266ca79886d873f6748 to your computer and use it in GitHub Desktop.
Calculations Example slim-redux-react v0.2
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
// computations/todo.js | |
import { compute } from 'slim-redux-react'; | |
export const visibleTodos = compute({ | |
todos: 'state.todos', | |
filter: 'state.filter', | |
}, () => { | |
// Notice how this function has no parameters, but returns a state computation | |
return todos.filter(todo => (filter === 'ALL' || ('filter' === 'COMPLETED' && todo.completed) || (filter === 'OPEN' && !todo.completed))) | |
}); | |
// components/TodoList.js | |
import { connect } from 'slim-redux-react'; | |
import { addTodo } from '../async/todo'; | |
import { visibleTodos } from '../computations/todo'; | |
// The TodoList react component | |
const TodoList = (props) => ( /* ... */ ); | |
// Connecting the visual component to the store | |
export const connect(TodoList, { visibleTodos }, { addTodo }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment