-
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.
Cleanup, used components from mobx-react-boilerplate
- Loading branch information
1 parent
b870bf7
commit c418c49
Showing
13 changed files
with
421 additions
and
2,682 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 |
---|---|---|
@@ -1,13 +1,3 @@ | ||
REACT_APP_DECORATORS = true; | ||
REACT_APP_BABEL_STAGE_0 = true; | ||
|
||
REACT_APP_SASS = false; | ||
REACT_APP_LESS = false; | ||
REACT_APP_STYLUS = false; | ||
|
||
REACT_APP_CSS_MODULES = true; | ||
REACT_APP_SASS_MODULES = false; | ||
REACT_APP_STYLUS_MODULES = false; | ||
REACT_APP_LESS_MODULES = false; | ||
|
||
REACT_APP_WEBPACK_DASHBOARD = true; |
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
Empty file.
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
import React, { Component } from "react"; | ||
import { observer } from "mobx-react"; | ||
|
||
const Todo = observer(({ todo }) => ( | ||
<li> | ||
<input | ||
type="checkbox" | ||
checked={todo.finished} | ||
onClick={() => (todo.finished = !todo.finished)} | ||
/> | ||
{todo.title} | ||
</li> | ||
)); | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { Component } from "react"; | ||
import { observable, action } from "mobx"; | ||
import { observer } from "mobx-react"; | ||
|
||
import Todo from "./Todo"; | ||
|
||
@observer | ||
class TodoList extends React.Component { | ||
@observable newTodoTitle = ""; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<form onSubmit={this.handleFormSubmit}> | ||
New Todo: | ||
<input | ||
type="text" | ||
value={this.newTodoTitle} | ||
onChange={this.handleInputChange} | ||
/> | ||
<button type="submit">Add</button> | ||
</form> | ||
<hr /> | ||
<ul> | ||
{this.props.store.todos.map(todo => ( | ||
<Todo todo={todo} key={todo.id} /> | ||
))} | ||
</ul> | ||
Tasks left: {this.props.store.unfinishedTodoCount} | ||
</div> | ||
); | ||
} | ||
|
||
@action | ||
handleInputChange = e => { | ||
this.newTodoTitle = e.target.value; | ||
}; | ||
|
||
@action | ||
handleFormSubmit = e => { | ||
this.props.store.addTodo(this.newTodoTitle); | ||
this.newTodoTitle = ""; | ||
e.preventDefault(); | ||
}; | ||
} | ||
|
||
export default TodoList; |
This file was deleted.
Oops, something went wrong.
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,39 +1,28 @@ | ||
import { observable, computed } from 'mobx'; | ||
import { Provider } from 'mobx-react'; | ||
import * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import TodoListView from "./TodoListView.js"; | ||
import registerServiceWorker from "./registerServiceWorker"; | ||
import React from "react"; | ||
import { render } from "react-dom"; | ||
import DevTools from "mobx-react-devtools"; | ||
|
||
import "./index.css"; | ||
import TodoList from "./components/TodoList"; | ||
import TodoListModel from "./models/TodoListModel"; | ||
import TodoModel from "./models/TodoModel"; | ||
|
||
const todoStore = title => { | ||
return { | ||
@observable title: title, | ||
@observable finished: false, | ||
id: Math.random() | ||
}; | ||
}; | ||
const store = new TodoListModel(); | ||
|
||
const todoListStore = { | ||
@observable todos: [], | ||
@computed get unfinishedTodoCount() { | ||
return todoListStore.todos.filter(todo => !todo.finished).length; | ||
} | ||
}; | ||
|
||
ReactDOM.render( | ||
<Provider todoListStore={todoListStore}> | ||
<TodoListView /> | ||
</Provider>, | ||
document.getElementById("root") | ||
render( | ||
<div> | ||
<DevTools /> | ||
<TodoList store={store} /> | ||
</div>, | ||
document.getElementById("root") | ||
); | ||
|
||
todoListStore.todos.push( | ||
todoStore("Get Coffee"), | ||
todoStore("Write simpler code") | ||
); | ||
store.addTodo("Get Coffee"); | ||
store.addTodo("Write simpler code"); | ||
store.todos[0].finished = true; | ||
|
||
todoListStore.todos[0].finished = true; | ||
setTimeout(() => { | ||
store.addTodo("Get a cookie as well"); | ||
}, 2000); | ||
|
||
registerServiceWorker(); | ||
// playing around in the console | ||
window.store = store; |
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,17 @@ | ||
import { observable, computed, action } from "mobx"; | ||
|
||
import TodoModel from "./TodoModel"; | ||
|
||
export default class TodoListModel { | ||
@observable todos = []; | ||
|
||
@computed | ||
get unfinishedTodoCount() { | ||
return this.todos.filter(todo => !todo.finished).length; | ||
} | ||
|
||
@action | ||
addTodo(title) { | ||
this.todos.push(new TodoModel(title)); | ||
} | ||
} |
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,11 @@ | ||
import { observable } from "mobx"; | ||
|
||
export default class TodoModel { | ||
id = Math.random(); | ||
@observable title; | ||
@observable finished = false; | ||
|
||
constructor(title) { | ||
this.title = title; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.