Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
20,562 additions
and
21,849 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,3 +1,4 @@ | ||
yarn-error.log | ||
coverage | ||
node_modules | ||
build |
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
This file was deleted.
Oops, something went wrong.
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
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,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<!-- | ||
manifest.json provides metadata used when your web app is added to the | ||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>TodoMVC in React</title> | ||
</head> | ||
|
||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
|
||
</html> |
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,116 @@ | ||
import React from "react"; | ||
import classnames from "classnames"; | ||
|
||
import { map, create, Store, valueOf } from "microstates"; | ||
import TodoMVC from "@microstates/todomvc"; | ||
|
||
import TodoTextInput from "./TodoTextInput"; | ||
|
||
const pluralize = (word, count) => (count === 1 ? word : `${word}s`); | ||
|
||
export default class App extends React.Component { | ||
state = { | ||
$: Store(create(TodoMVC, this.props.value), $ => { | ||
this.setState({ $ }); | ||
this.props.onChange(valueOf($)); | ||
}) | ||
} | ||
render() { | ||
let { $ } = this.state; | ||
return ( | ||
<div className="todoapp"> | ||
<header className="header"> | ||
<h1>todos</h1> | ||
<TodoTextInput | ||
text={$.newTodo.state} | ||
classes="new-todo" | ||
onSave={$.insertNewTodo} | ||
onBlur={$.insertNewTodo} | ||
onInputChange={$.newTodo.set} | ||
placeholder="What needs to be done?" | ||
/> | ||
</header> | ||
<section className="main"> | ||
{$.hasTodos && ( | ||
<span> | ||
<input | ||
id="toggle-all" | ||
className="toggle-all" | ||
type="checkbox" | ||
checked={$.isAllComplete} | ||
onChange={$.toggleAll} | ||
/> | ||
<label htmlFor="toggle-all" /> | ||
</span> | ||
)} | ||
<ul className="todo-list"> | ||
{map($.filtered, todo => ( | ||
<li | ||
className={classnames({ | ||
completed: todo.completed.state, | ||
editing: todo.editing.state | ||
})} | ||
key={todo.id.state} | ||
> | ||
{todo.editing.state ? ( | ||
<TodoTextInput | ||
text={todo.text.state} | ||
classes="edit" | ||
onSave={todo.save} | ||
onBlur={todo.save} | ||
onInputChange={todo.text.set} | ||
/> | ||
) : ( | ||
<div className="view"> | ||
<input | ||
className="toggle" | ||
type="checkbox" | ||
checked={todo.completed.state} | ||
onChange={todo.completed.toggle} | ||
/> | ||
<label onDoubleClick={todo.edit}>{todo.text.state}</label> | ||
<button | ||
className="destroy" | ||
onClick={() => | ||
$.todos.filter(item => todo.state !== item.state) | ||
} | ||
/> | ||
</div> | ||
)} | ||
</li> | ||
))} | ||
</ul> | ||
{$.hasTodos && ( | ||
<footer className="footer"> | ||
<span className="todo-count"> | ||
<strong>{$.active.length || "No"}</strong>{" "} | ||
{pluralize("item", $.active.length)} | ||
</span> | ||
<ul className="filters"> | ||
{$.filters.map(filter => ( | ||
<li key={filter.key}> | ||
<button | ||
className={classnames({ selected: filter.selected })} | ||
style={{ cursor: "pointer" }} | ||
onClick={filter.select} | ||
> | ||
{filter.label} | ||
</button> | ||
</li> | ||
))} | ||
</ul> | ||
{$.hasCompleted && ( | ||
<button | ||
className="clear-completed" | ||
onClick={$.clearCompleted} | ||
> | ||
Clear completed | ||
</button> | ||
)} | ||
</footer> | ||
)} | ||
</section> | ||
</div> | ||
) | ||
} | ||
} |
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
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,18 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import App from "./App"; | ||
import "./styles.css"; | ||
|
||
let key = "microstates-todomvc"; | ||
|
||
let restore = () => JSON.parse(localStorage.getItem(key) || "null"); | ||
let save = value => localStorage.setItem(key, JSON.stringify(value)); | ||
|
||
let initial = restore() || { | ||
todos: [{ id: 0, text: "Write Microstates Docs", completed: false }] | ||
}; | ||
|
||
ReactDOM.render( | ||
<App value={initial} onChange={save} />, | ||
document.getElementById("root") | ||
); |
File renamed without changes.
Oops, something went wrong.