Skip to content

Instantly share code, notes, and snippets.

@aGuyNamedJonas
Created May 16, 2017 13:28
Show Gist options
  • Save aGuyNamedJonas/f12e06aed26bf266ca79886d873f6748 to your computer and use it in GitHub Desktop.
Save aGuyNamedJonas/f12e06aed26bf266ca79886d873f6748 to your computer and use it in GitHub Desktop.
Calculations Example slim-redux-react v0.2
// 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