Skip to content

Commit

Permalink
Cleanup, used components from mobx-react-boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Aug 31, 2017
1 parent b870bf7 commit c418c49
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 2,682 deletions.
10 changes: 0 additions & 10 deletions .env
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;
2,155 changes: 3 additions & 2,152 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"custom-react-scripts": "0.2.0",
"mobx": "^3.2.2",
"mobx-react": "^4.2.2",
"mobx-react-devtools": "^4.2.15",
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
Expand Down
Empty file removed src/TodoListView.css
Empty file.
35 changes: 0 additions & 35 deletions src/TodoListView.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/components/Todo.jsx
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;
47 changes: 47 additions & 0 deletions src/components/TodoList.jsx
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;
5 changes: 0 additions & 5 deletions src/index.css

This file was deleted.

53 changes: 21 additions & 32 deletions src/index.js
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;
17 changes: 17 additions & 0 deletions src/models/TodoListModel.js
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));
}
}
11 changes: 11 additions & 0 deletions src/models/TodoModel.js
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;
}
}
108 changes: 0 additions & 108 deletions src/registerServiceWorker.js

This file was deleted.

Loading

0 comments on commit c418c49

Please sign in to comment.