Created
June 22, 2016 21:12
-
-
Save fson/576eda4a5401fd078c18101cdda558e0 to your computer and use it in GitHub Desktop.
A todo app example with frzr and JSX.
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
Show hidden characters
{ | |
"plugins": [ | |
"syntax-jsx", | |
["transform-react-jsx", { "pragma": "frzr.el" }] | |
], | |
"presets": ["es2015"] | |
} |
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
<html> | |
<head> | |
<title>frzr with JSX</title> | |
<link href="todo.css" rel="stylesheet"> | |
</head> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/frzr/0.20.0/frzr.js"></script> | |
<script src="bundle.js"></script> | |
</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
{ | |
"name": "frzr-jsx-demo", | |
"version": "0.0.1", | |
"scripts": { | |
"build": "babel todo.js > bundle.js", | |
"postinstall": "npm run build" | |
}, | |
"license": "MIT", | |
"devDependencies": { | |
"babel-cli": "^6.10.1", | |
"babel-plugin-syntax-jsx": "^6.8.0", | |
"babel-plugin-transform-react-jsx": "^6.8.0", | |
"babel-preset-es2015": "^6.9.0" | |
} | |
} |
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
body { | |
font-family: sans-serif; | |
} | |
.todo.done .title { | |
text-decoration: line-through; | |
} | |
.todo input[type="checkbox"] { | |
float: left; | |
margin-right: .5rem; | |
} |
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
class Todo { | |
constructor() { | |
this.el = ( | |
<div className="todo"> | |
{this.done = <input type="checkbox" />} | |
{this.title = <p className="title" />} | |
</div> | |
); | |
this.done.onchange = () => { | |
this.data.done = this.done.checked; | |
this.update(this.data); | |
}; | |
} | |
update(data) { | |
this.data = data; | |
this.done.checked = data.done; | |
this.title.textContent = data.title; | |
if (data.done) { | |
this.el.classList.add('done'); | |
} else { | |
this.el.classList.remove('done'); | |
} | |
} | |
} | |
class TodoApp { | |
constructor() { | |
this.data = []; | |
this.el = ( | |
<div className="todo-app"> | |
<h1>Todo</h1> | |
<div className="todos"> | |
{this.todoList = new frzr.List(Todo)} | |
</div> | |
{this.create = | |
<form> | |
{this.createInput = <input placeholder="Something to do" />} | |
<button>Add</button> | |
</form> | |
} | |
{this.clear = <button>Clear done</button>} | |
</div> | |
); | |
this.create.onsubmit = () => { | |
this.data.push({ | |
done: false, | |
title: this.createInput.value, | |
}); | |
this.update(this.data); | |
this.createInput.value = ''; | |
return false; | |
}; | |
this.clear.onclick = () => { | |
this.update(this.data.filter((item) => !item.done)); | |
}; | |
} | |
update(data) { | |
this.data = data; | |
this.todoList.update(data); | |
} | |
} | |
const app = new TodoApp(); | |
frzr.mount(document.body, app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment