diff --git a/src/actions.js b/src/actions/todo/index.js similarity index 98% rename from src/actions.js rename to src/actions/todo/index.js index 11cc0eb..03ef09f 100644 --- a/src/actions.js +++ b/src/actions/todo/index.js @@ -1,4 +1,3 @@ - export function addTodo(text) { return { type: 'ADD_TODO', @@ -11,4 +10,4 @@ export function removeTodo(todo) { type: 'REMOVE_TODO', todo }; -} +} \ No newline at end of file diff --git a/src/components/app.js b/src/components/app.js index aab7733..07453e0 100644 --- a/src/components/app.js +++ b/src/components/app.js @@ -1,10 +1,11 @@ import { h, Component } from 'preact'; import { connect } from 'preact-redux'; -import reduce from '../reducers'; -import * as actions from '../actions'; +import reduce from '../reducers/reducers'; +import * as actions from '../actions/todo'; import TodoItem from './todo-item'; @connect(reduce, actions) + export default class App extends Component { addTodos = () => { this.props.addTodo(this.state.text); @@ -33,4 +34,4 @@ export default class App extends Component { ); } -} +} \ No newline at end of file diff --git a/src/components/todo-item.js b/src/components/todo-item.js index 79ccc7d..5bb170f 100644 --- a/src/components/todo-item.js +++ b/src/components/todo-item.js @@ -18,4 +18,4 @@ export default class TodoItem extends Component { ); } -} +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 2597494..dfe6807 100755 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ import { Provider } from 'preact-redux'; -import store from './store'; +import store from './reducers/store'; import App from './components/app'; import './style'; @@ -9,4 +9,4 @@ export default () => ( -); +); \ No newline at end of file diff --git a/src/reducers.js b/src/reducers.js deleted file mode 100644 index 8da1ff1..0000000 --- a/src/reducers.js +++ /dev/null @@ -1,4 +0,0 @@ - -const EMPTY = {}; - -export default store => store || EMPTY; diff --git a/src/reducers/reducers.js b/src/reducers/reducers.js new file mode 100644 index 0000000..eb7423d --- /dev/null +++ b/src/reducers/reducers.js @@ -0,0 +1,3 @@ +const EMPTY = {}; + +export default store => store || EMPTY; \ No newline at end of file diff --git a/src/reducers/store.js b/src/reducers/store.js new file mode 100644 index 0000000..99c3ee4 --- /dev/null +++ b/src/reducers/store.js @@ -0,0 +1,15 @@ +import { createStore } from 'redux'; +import {ADD_TODO, REMOVE_TODO} from './todo' + +const ACTIONS = { + ADD_TODO, + REMOVE_TODO +} + +const INITIAL = { + todos: [] +}; + +export default createStore( (state, action) => ( + action && ACTIONS[action.type] ? ACTIONS[action.type](state, action) : state +), INITIAL, typeof devToolsExtension==='function' ? devToolsExtension() : undefined); \ No newline at end of file diff --git a/src/reducers/todo.js b/src/reducers/todo.js new file mode 100644 index 0000000..83367b8 --- /dev/null +++ b/src/reducers/todo.js @@ -0,0 +1,17 @@ + + +const ADD_TODO = ({ todos, ...state }, { text }) => ({ + todos: [...todos, { + id: Math.random().toString(36).substring(2), + text + }], + ...state + }) + +const REMOVE_TODO = ({ todos, ...state }, { todo }) => ({ + todos: todos.filter( i => i!==todo ), + ...state + }) + + +export {ADD_TODO, REMOVE_TODO } \ No newline at end of file diff --git a/src/store.js b/src/store.js deleted file mode 100644 index 7b20d57..0000000 --- a/src/store.js +++ /dev/null @@ -1,24 +0,0 @@ -import { createStore } from 'redux'; - -let ACTIONS = { - ADD_TODO: ({ todos, ...state }, { text }) => ({ - todos: [...todos, { - id: Math.random().toString(36).substring(2), - text - }], - ...state - }), - - REMOVE_TODO: ({ todos, ...state }, { todo }) => ({ - todos: todos.filter( i => i!==todo ), - ...state - }) -}; - -const INITIAL = { - todos: [] -}; - -export default createStore( (state, action) => ( - action && ACTIONS[action.type] ? ACTIONS[action.type](state, action) : state -), INITIAL, typeof devToolsExtension==='function' ? devToolsExtension() : undefined);