Commit ce5a6809 authored by Sindre Sorhus's avatar Sindre Sorhus

Followup to #655

parent 85e66a4e
...@@ -6,6 +6,5 @@ label { ...@@ -6,6 +6,5 @@ label {
-webkit-user-select: none; -webkit-user-select: none;
-moz-user-select: none; -moz-user-select: none;
-ms-user-select: none; -ms-user-select: none;
-o-user-select: none;
user-select: none; user-select: none;
} }
\ No newline at end of file
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
<section id="todoapp"></section> <section id="todoapp"></section>
<footer id="info"> <footer id="info">
<p>Double-click to edit a todo</p> <p>Double-click to edit a todo</p>
<p>Created by <a href="http://rich-harris.co.uk">Rich Harris</a></p> <p>Created by <a href="http://rich-harris.co.uk">Rich Harris</a></p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p> <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer> </footer>
...@@ -21,19 +20,16 @@ ...@@ -21,19 +20,16 @@
<header id="header"> <header id="header">
<h1>todos</h1> <h1>todos</h1>
<!-- In app.js, we define a custom `enter` event, which fires when the user <!-- In app.js, we define a custom `enter` event, which fires when the user hits the enter key, submitting a new todo. -->
hits the enter key, submitting a new todo -->
<input id="new-todo" on-enter="newTodo" placeholder="What needs to be done?" autofocus> <input id="new-todo" on-enter="newTodo" placeholder="What needs to be done?" autofocus>
</header> </header>
<!-- We only render the main section and the footer if we have one or more todos - <!--
in other words, `items.length` is not falsy --> We only render the main section and the footer if we have one or more todos - in other words, `items.length` is not falsy.
-->
{{#items.length}} {{#items.length}}
<section id="main"> <section id="main">
<!-- Here, we compare the total number of tasks (`items.length`) with the number of <!-- Here, we compare the total number of tasks (`items.length`) with the number of completed tasks (`completedTasks().length`). This calculation happens reactively, so we never need to manually trigger an update. When the `change` event fires on the input, the `toggleAll` event fires on the Ractive instance. -->
completed tasks (`completedTasks().length`). This calculation happens reactively,
so we never need to manually trigger an update. When the `change` event fires
on the input, the `toggleAll` event fires on the Ractive instance. -->
<input id="toggle-all" type="checkbox" on-change="toggleAll" checked='{{ items.length === completedTasks().length }}'> <input id="toggle-all" type="checkbox" on-change="toggleAll" checked='{{ items.length === completedTasks().length }}'>
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
...@@ -75,10 +71,8 @@ ...@@ -75,10 +71,8 @@
</script> </script>
<script id="item" type="text/ractive"> <script id="item" type="text/ractive">
<!-- This is the {{>item}} partial. It is rendered for each task in the array <!-- This is the {{>item}} partial. It is rendered for each task in the array (`this` corresponds to the current task). But we only want to actually show those tasks that pass the current filter. -->
(`this` corresponds to the current task). But we only want to actually show {{# filter(this) }}
those tasks that pass the current filter. -->
{{# filter( this ) }}
<li class="{{ completed ? 'completed' : '' }} {{ editing ? 'editing' : '' }}"> <li class="{{ completed ? 'completed' : '' }} {{ editing ? 'editing' : '' }}">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" checked="{{completed}}"> <input class="toggle" type="checkbox" checked="{{completed}}">
...@@ -88,8 +82,7 @@ ...@@ -88,8 +82,7 @@
<!-- This section only exists in the DOM when editing is taking place --> <!-- This section only exists in the DOM when editing is taking place -->
{{#.editing}} {{#.editing}}
<!-- Here, we use custom events (`enter`) alongside standard DOM events <!-- Here, we use custom events (`enter`) alongside standard DOM events (`blur`) to handle user interaction -->
(`blur`) to handle user interaction -->
<input id="edit" class="edit" on-blur-enter="submit" on-escape="cancel" autofocus> <input id="edit" class="edit" on-blur-enter="submit" on-escape="cancel" autofocus>
{{/.editing}} {{/.editing}}
</li> </li>
......
/*global window, Ractive */ /*global window, Ractive */
(function (window, Ractive) { (function (window, Ractive) {
'use strict'; 'use strict';
// Create some filter functions, which we'll need later // Create some filter functions, which we'll need later
var filters = { var filters = {
completed: function (item) { return item.completed; }, completed: function (item) { return item.completed; },
active: function (item) { return !item.completed; } active: function (item) { return !item.completed; }
}; };
// The keycode for the 'enter' and 'escape' keys // The keycode for the 'enter' and 'escape' keys
var ENTER_KEY = 13, ESCAPE_KEY = 27; var ENTER_KEY = 13;
var ESCAPE_KEY = 27;
// Create our Ractive instance // Create our Ractive instance
var todoList = new Ractive({ var todoList = new Ractive({
// Specify a target element - an ID, a CSS selector, or the element itself // Specify a target element - an ID, a CSS selector, or the element itself
el: 'todoapp', el: 'todoapp',
...@@ -167,4 +165,4 @@ ...@@ -167,4 +165,4 @@
window.todoList = todoList; window.todoList = todoList;
})(window, Ractive); })(window, Ractive);
\ No newline at end of file
/*global window, todoList */ /*global window, todoList */
(function (window, todoList) { (function (window, todoList) {
'use strict'; 'use strict';
// In Ractive, 'models' are usually just POJOs - plain old JavaScript objects. // In Ractive, 'models' are usually just POJOs - plain old JavaScript objects.
...@@ -34,16 +32,14 @@ ...@@ -34,16 +32,14 @@
// Whenever the model changes (including child properties like // Whenever the model changes (including child properties like
// `items[1].completed`)... // `items[1].completed`)...
todoList.observe('items', function (items) { todoList.observe('items', function (items) {
// ...we persist it to localStorage // ...we persist it to localStorage
localStorage.setItem('todos-ractive', JSON.stringify(items.map(removeEditingState))); localStorage.setItem('todos-ractive', JSON.stringify(items.map(removeEditingState)));
}); });
} } else {
else {
items = []; items = [];
} }
todoList.set('items', items); todoList.set('items', items);
}(window, todoList)); })(window, todoList);
\ No newline at end of file
/*global window, Router, todoList */ /*global window, Router, todoList */
(function (window, Router, todoList) { (function (window, Router, todoList) {
'use strict'; 'use strict';
// We're using https://github.com/flatiron/director for routing // We're using https://github.com/flatiron/director for routing
...@@ -24,4 +22,4 @@ ...@@ -24,4 +22,4 @@
router.init(); router.init();
}(window, Router, todoList)); })(window, Router, todoList);
\ No newline at end of file
# Ractive.js TodoMVC Example # Ractive.js TodoMVC app
> Ractive.js solves some of the biggest headaches in web development – data binding, efficient DOM updates, event handling – and does so with almost no learning curve. > Ractive.js solves some of the biggest headaches in web development – data binding, efficient DOM updates, event handling – and does so with almost no learning curve.
...@@ -24,6 +24,7 @@ This is because Ractive is optimised for developer sanity (as well as performanc ...@@ -24,6 +24,7 @@ This is because Ractive is optimised for developer sanity (as well as performanc
It has a number of innovative features: animations, easier event handling, declarative transitions, first-class SVG support, logical expressions in templates with sophisticated dependency tracking. For many developers, it hits the sweet spot between the flexibility of a library like Backbone and the power of a framework like Angular. It has a number of innovative features: animations, easier event handling, declarative transitions, first-class SVG support, logical expressions in templates with sophisticated dependency tracking. For many developers, it hits the sweet spot between the flexibility of a library like Backbone and the power of a framework like Angular.
## Credit ## Credit
This TodoMVC application was created by [Rich Harris](http://rich-harris.co.uk). This TodoMVC application was created by [Rich Harris](http://rich-harris.co.uk).
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment