Last active
February 15, 2016 02:33
-
-
Save laere/7177445c0162624dec93 to your computer and use it in GitHub Desktop.
Revisions
-
laere revised this gist
Feb 15, 2016 . 3 changed files with 23 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,27 +1,28 @@ import dotProp from 'dot-prop-immutable'; //save string values to vars const ADD_TODO = 'ADD_TODO'; let nextId = 0; //the action is whats performed to alter state //addItem is an action creator and nees to return an action export const AddTodo = (text) => { return { type: ADD_TODO, id: nextId++, text }; } //initial state of items and text const initialState = { items: [], } //A pure function that takes the current/prev state //and an action, and returns the next state //Reducer controls the state, and is where state lives. export const ToDoState = (state = initialState, action) => { switch(action.type) { case ADD_TODO: state = dotProp.set(state, 'items', items => [...items, {text: action.text, id: action.id }]) console.log(state, action); return state; default: This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,8 +13,7 @@ class App extends Component { } handleSubmit(e) { this.props.AddTodo(); } render() { @@ -23,7 +22,7 @@ class App extends Component { <h1>To Do App</h1> <List items={this.props.items} handleSubmit={this.handleSubmit} /> </div> ) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,19 @@ import ListItem from '../components/ListItem'; export default class List extends Component { constructor(props) { super(props); this.handleOnClick = this.handleOnClick.bind(this); } handleOnClick(e) { e.preventDefault(); let inputValue = this.refs.inputfield.value; this.props.handleSubmit(inputValue); console.log(inputValue); } renderTodos() { return this.props.items.map((item) => { return ( @@ -14,7 +27,7 @@ export default class List extends Component { render() { return ( <div> <form onSubmit={this.handleOnClick}> <input type="text" ref="inputfield"/> <input type="submit" value="Add" /> </form> -
laere revised this gist
Feb 15, 2016 . 2 changed files with 5 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,7 @@ const ADD_TODO = 'ADD_TODO'; let nextId = 0; export const AddTodo = (text) => { return { type: ADD_TODO, @@ -18,9 +17,7 @@ const initialState = { items: [], text: '' } export const ToDoState = (state = initialState, action) => { switch(action.type) { case ADD_TODO: This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,20 @@ import React, { Component } from 'react'; import { AddTodo } from '../reducers/reducer_todos'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import List from '../containers/List'; class App extends Component { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); } handleSubmit(e) { e.preventDefault(); this.props.AddTodo(this.refs.inputfield.value); } render() { @@ -26,7 +23,7 @@ class App extends Component { <h1>To Do App</h1> <List items={this.props.items} handleOnClick={this.handleSubmit} /> </div> ) -
laere revised this gist
Feb 15, 2016 . No changes.There are no files selected for viewing
-
laere revised this gist
Feb 15, 2016 . 4 changed files with 16 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ //save string values to vars const ADD_TODO = 'ADD_TODO'; let nextId = 0; //the action is whats performed to alter state //addItem is an action creator and nees to return an action export const AddTodo = (text) => { return { type: ADD_TODO, @@ -13,25 +13,19 @@ export const AddTodo = (text) => { }; } //initial state of items and text const initialState = { items: [], text: '' } //A pure function that takes the current/prev state //and an action, and returns the next state //Reducer controls the state, and is where state lives. export const ToDoState = (state = initialState, action) => { switch(action.type) { case ADD_TODO: state = dotProp.set(state, 'items', items => [...items, { text: action.text, id: action.id }]); console.log(state, action); return state; default: return state; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,6 @@ import React, { Component } from 'react'; //import actions import { AddTodo } from '../reducers/reducer_todos'; // import { RemoveToDo } from '../reducers/reducer_todos'; //connect to store import { connect } from 'react-redux'; @@ -17,20 +14,10 @@ class App extends Component { super(props); } handleSubmit(e) { e.preventDefault(); this.props.AddTodo(this.refs.inputfield.value); this.refs.inputfield.value = '' } render() { @@ -39,8 +26,7 @@ class App extends Component { <h1>To Do App</h1> <List items={this.props.items} handleSubmit={this.props.handleSubmit} /> </div> ) @@ -50,8 +36,7 @@ class App extends Component { let mapDispatchToProps = (dispatch) => { return bindActionCreators( { AddTodo: AddTodo }, dispatch); } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,9 +14,9 @@ export default class List extends Component { render() { return ( <div> <form onSubmit={this.props.handleSubmit}> <input type="text" ref="inputfield"/> <input type="submit" value="Add" /> </form> <ul> {this.renderTodos()} This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ export default class ListItem extends Component { render() { return ( <li> {this.props.text} </li> ); } -
laere revised this gist
Feb 14, 2016 . 2 changed files with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const UPDATE_TEXT = 'UPDATE_TEXT'; let nextId = 0; export const AddTodo = (text) => { return { type: ADD_TODO, id: nextId++, This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,8 @@ import React, { Component } from 'react'; //import actions import { UpdateText } from '../reducers/reducer_todos'; import { AddTodo } from '../reducers/reducer_todos'; // import { RemoveToDo } from '../reducers/reducer_todos'; //connect to store @@ -51,7 +50,7 @@ class App extends Component { let mapDispatchToProps = (dispatch) => { return bindActionCreators( { AddTodo: AddTodo, UpdateText: UpdateText }, dispatch); } -
laere revised this gist
Feb 14, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ //save string values to vars const ADD_TODO = 'ADD_TODO'; const UPDATE_TEXT = 'UPDATE_TEXT'; let nextId = 0; -
laere revised this gist
Feb 14, 2016 . 5 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
laere created this gist
Feb 14, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ import React, { Component } from 'react'; //import actions import { UpdateText } from '../reducers/reducer_todos'; import { AddToDo } from '../reducers/reducer_todos'; console.log(AddToDo); console.log(UpdateText); // import { RemoveToDo } from '../reducers/reducer_todos'; //connect to store import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; //import List component import List from '../containers/List'; class App extends Component { constructor(props) { super(props); } handleOnChange(e) { this.props.UpdateText(e.target.value); console.log(e.target.value); } handleOnClick(e) { e.preventDefault(); this.props.AddTodo(this.getInputText()); console.log('test click'); } getInputText() { return this.refs.inputfield.value; console.log(this.refs.inputfield.value); } render() { return ( <div> <h1>To Do App</h1> <List items={this.props.items} handleOnClick={this.props.handleOnClick} handleOnChange={this.props.handleOnChange} /> </div> ) } } let mapDispatchToProps = (dispatch) => { return bindActionCreators( { AddToDo: AddToDo, UpdateText: UpdateText }, dispatch); } let mapStateToProps = (state) => { return { items: state.items, text: state.text } } export default connect(mapStateToProps, mapDispatchToProps)(App); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ import React, { Component } from 'react'; import ListItem from '../components/ListItem'; export default class List extends Component { renderTodos() { return this.props.items.map((item) => { return ( <ListItem key={item.id} text={item.text} /> ); }); } render() { return ( <div> <form> <input onChange={this.props.handleOnChange} ref="inputfield"/> <button onClick={this.props.handleOnClick} >Add</button> </form> <ul> {this.renderTodos()} </ul> </div> ); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ import React, { Component } from 'react'; export default class ListItem extends Component { render() { return ( <li> <h4>{this.props.text}</h4> </li> ); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ //save string values to vars const ADD_TODO = 'ADD_TODO'; const UPDATE_TEXT = 'UPDATE_TEXT'; const REMOVE_TODO = 'REMOVE_TODO'; let nextId = 0; export const AddToDo = (text) => { return { type: ADD_TODO, id: nextId++, text }; } export const UpdateText = (text) => { return { type: UPDATE_TEXT, text }; } const initialState = { items: [], text: '' } export const ToDoState = (state = initialState, action) => { switch(action.type) { case ADD_TODO: state = dotProp.set(state, 'items', items => [...items, { text: action.text, id: action.id }]); return state; case UPDATE_TEXT: state.UpdateText = action.text; return state; default: return state; } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import React from 'react'; import ReactDOM from 'react-dom'; import App from './components/app'; import dotProp from 'dot-prop-immutable'; import { Provider } from 'react-redux'; import { createStore } from 'redux'; import { ToDoState } from '../src/reducers/reducer_todos'; let store = createStore(ToDoState); console.log(store); ReactDOM.render( <Provider store={store}> <App /> </Provider>, document.querySelector('.container'));