Commit 9803689b authored by Sindre Sorhus's avatar Sindre Sorhus

rAppid.js app clenup and improve readme

parent 89083b70
<?xml version="1.0"?> <?xml version="1.0"?>
<app:TodoClass xmlns="http://www.w3.org/1999/xhtml" <app:TodoClass xmlns="http://www.w3.org/1999/xhtml"
xmlns:js="js.core" xmlns:ui="js.ui" xmlns:app="app" xmlns:view="app.view" xmlns:conf="js.conf" xmlns:js="js.core" xmlns:ui="js.ui" xmlns:app="app" xmlns:view="app.view" xmlns:conf="js.conf"
xmlns:data="js.data"> xmlns:data="js.data">
<!-- LOCAL STORAGE CONFIGURATION --> <!-- LOCAL STORAGE CONFIGURATION -->
<data:LocalStorageDataSource cid="dataSource" name="todo-rappidjs"> <data:LocalStorageDataSource cid="dataSource" name="todo-rappidjs">
<conf:Configuration path="todos" modelClassName="app.model.Todo" <conf:Configuration path="todos" modelClassName="app.model.Todo"
collectionClassName="app.collection.TodoList"/> collectionClassName="app.collection.TodoList"/>
</data:LocalStorageDataSource> </data:LocalStorageDataSource>
<!-- ROUTER CONFIGURATION --> <!-- ROUTER CONFIGURATION -->
<js:Router cid="router"> <js:Router cid="router">
<conf:Route name="default" route="^$" onexec="showAll"/> <conf:Route name="default" route="^$" onexec="showAll"/>
<conf:Route name="active" route="^active$" onexec="showActive"/> <conf:Route name="active" route="^active$" onexec="showActive"/>
<conf:Route name="completed" route="^completed$" onexec="showCompleted"/> <conf:Route name="completed" route="^completed$" onexec="showCompleted"/>
</js:Router> </js:Router>
<!-- HERE WE START TO DEFINE THE UI WITH HTML AND CUSTOM UI COMPONENTS --> <!-- HERE WE START TO DEFINE THE UI WITH HTML AND CUSTOM UI COMPONENTS -->
<section id="todoapp"> <section id="todoapp">
<header id="header"> <header id="header">
<h1>Todos</h1> <h1>Todos</h1>
<input id="new-todo" placeholder="What needs to be done?" type="text" onkeyup="addNewTodo" autofocus="autofocus"/> <input id="new-todo" placeholder="What needs to be done?" type="text" onkeyup="addNewTodo" autofocus="autofocus"/>
</header> </header>
<section id="main" visible="{todoList.hasItems()}"> <section id="main" visible="{todoList.hasItems()}">
<input id="toggle-all" type="checkbox" onclick="markAllComplete" <input id="toggle-all" type="checkbox" onclick="markAllComplete"
checked="{todoList.areAllComplete()}"/> checked="{todoList.areAllComplete()}"/>
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<!-- CUSTOM UI COMPONENT FOR RENDERING A LIST OF ITEMS -> TODOs --> <!-- CUSTOM UI COMPONENT FOR RENDERING A LIST OF ITEMS -> TODOs -->
<ui:ItemsView items="{filterList.list}" tagName="ul" id="todo-list" itemKey="todo"> <ui:ItemsView items="{filterList.list}" tagName="ul" id="todo-list" itemKey="todo">
<js:Template name="item"> <js:Template name="item">
<view:TodoView todo="{$todo}" tagName="li" onremove="removeTodo"/> <view:TodoView todo="{$todo}" tagName="li" onremove="removeTodo"/>
</js:Template> </js:Template>
</ui:ItemsView> </ui:ItemsView>
</section> </section>
<footer id="footer" data-num="{todoList.numOpenTodos()}" visible="{todoList.hasItems()}"> <footer id="footer" data-num="{todoList.numOpenTodos()}" visible="{todoList.hasItems()}">
<span id="todo-count"> <span id="todo-count">
<strong>{data-num}</strong> {translateItems({data-num})} left <strong>{data-num}</strong> {translateItems({data-num})} left
</span> </span>
<ul id="filters"> <ul id="filters">
<li> <li>
<a href="#/" class="{selectedClass('all',{filterList.filter})}">All</a> <a href="#/" class="{selectedClass('all',{filterList.filter})}">All</a>
</li> </li>
<li> <li>
<a href="#/active" class="{selectedClass('active',{filterList.filter})}">Active</a> <a href="#/active" class="{selectedClass('active',{filterList.filter})}">Active</a>
</li> </li>
<li> <li>
<a href="#/completed" class="{selectedClass('completed',{filterList.filter})}">Completed</a> <a href="#/completed" class="{selectedClass('completed',{filterList.filter})}">Completed</a>
</li> </li>
</ul> </ul>
<button id="clear-completed" onclick="clearCompleted" visible="{todoList.hasCompletedTodos()}"> <button id="clear-completed" onclick="clearCompleted" visible="{todoList.hasCompletedTodos()}">
Clear completed ({todoList.numCompletedTodos()}) Clear completed ({todoList.numCompletedTodos()})
</button> </button>
</footer> </footer>
</section> </section>
<footer id="info"> <footer id="info">
<p visible="{todoList.hasItems()}">Double - click to edit a todo</p> <p visible="{todoList.hasItems()}">Double - click to edit a todo</p>
<p>Template by <a href="http://github.com/sindresorhus">Sindre Sorhus</a></p> <p>Template by <a href="http://github.com/sindresorhus">Sindre Sorhus</a></p>
<p> <p>
Created by <a href="http://github.com/krebbl">Marcus Krejpowicz</a> with<a href="http://rappidjs.com">&lt; rAppid:js/&gt;</a> Created by <a href="http://github.com/krebbl">Marcus Krejpowicz</a> with<a href="http://rappidjs.com">&lt; rAppid:js/&gt;</a>
<br/> <br/>
Big credits to <a href="http://github.com/it-ony">Tony Findeisen</a> Big credits to <a href="http://github.com/it-ony">Tony Findeisen</a>
</p> </p>
<p>Part of <p>Part of
<a href="http://todomvc.com">TodoMVC</a> <a href="http://todomvc.com">TodoMVC</a>
</p> </p>
</footer> </footer>
</app:TodoClass> </app:TodoClass>
\ No newline at end of file
define(["js/core/Application", "js/core/I18n", "app/model/Todo", "app/collection/TodoList", "js/data/FilterDataView", "js/data/LocalStorageDataSource"], define([
function (Application, I18n, Todo, TodoList, FilterDataView, DataSource) { 'js/core/Application',
'app/model/Todo',
'app/collection/TodoList',
'js/data/FilterDataView',
'js/data/LocalStorageDataSource'
], function ( Application, Todo, TodoList, FilterDataView, DataSource ) {
var ENTER_KEY = 13; var ENTER_KEY = 13;
return Application.inherit("app.TodoClass", { return Application.inherit('app.TodoClass', {
/** /**
* Initializes the app * Initializes the app
* In this method we set the initial models * In this method we set the initial models
*/ */
initialize: function () { initialize: function() {
this.set("todoList", null); this.set( 'todoList', null );
this.set("filterList", null); this.set( 'filterList', null );
this.callBase(); this.callBase();
}, },
/** /**
* Are triggered * Are triggered
*/ */
showAll: function () { showAll: function () {
this.$.filterList.set("filter", 'all'); this.$.filterList.set("filter", 'all');
}, },
showActive: function () { showActive: function () {
this.$.filterList.set("filter", "active"); this.$.filterList.set("filter", "active");
}, },
showCompleted: function () { showCompleted: function () {
this.$.filterList.set("filter", "completed"); this.$.filterList.set("filter", "completed");
}, },
/** /**
* The rest is just controller stuff * The rest is just controller stuff
*/ */
addNewTodo: function (e) { addNewTodo: function (e) {
if (e.domEvent.keyCode === ENTER_KEY) { if (e.domEvent.keyCode === ENTER_KEY) {
var title = e.target.get("value").trim(); var title = e.target.get("value").trim();
if (title) { if (title) {
var newTodo = this.$.dataSource.createEntity(Todo); var newTodo = this.$.dataSource.createEntity(Todo);
newTodo.set({title: title, completed: false}); newTodo.set({title: title, completed: false});
this.get("todoList").add(newTodo); this.get("todoList").add(newTodo);
// save the new item // save the new item
newTodo.save(); newTodo.save();
e.target.set('value',''); e.target.set('value','');
} }
} }
}, },
markAllComplete: function (e) { markAllComplete: function (e) {
this.get("todoList").markAll(e.target.$el.checked); this.get("todoList").markAll(e.target.$el.checked);
}, },
clearCompleted: function () { clearCompleted: function () {
this.get("todoList").clearCompleted(); this.get("todoList").clearCompleted();
}, },
removeTodo: function (e) { removeTodo: function (e) {
var todo = e.$, self = this; var todo = e.$, self = this;
todo.remove(null, function(err){ todo.remove(null, function(err){
if(!err){ if(!err){
self.get("todoList").remove(todo); self.get("todoList").remove(todo);
} }
}); });
}, },
/** /**
* Start the application and render it to the body ... * Start the application and render it to the body ...
*/ */
start: function (parameter, callback) { start: function (parameter, callback) {
this.set('todoList', this.$.dataSource.createCollection(TodoList)); this.set('todoList', this.$.dataSource.createCollection(TodoList));
// fetch all todos, can be done sync because we use localStorage // fetch all todos, can be done sync because we use localStorage
this.$.todoList.fetch(); this.$.todoList.fetch();
this.set('filterList', new FilterDataView({ this.set('filterList', new FilterDataView({
baseList: this.get("todoList"), baseList: this.get("todoList"),
filter: 'all', filter: 'all',
filterFnc: function (item) { filterFnc: function (item) {
var filter = this.$.filter; var filter = this.$.filter;
if (filter == "active") { if (filter == "active") {
return !item.isCompleted(); return !item.isCompleted();
} else if (filter == "completed") { } else if (filter == "completed") {
return item.isCompleted(); return item.isCompleted();
} else { } else {
return true; return true;
} }
}}) }})
); );
// false - disables autostart // false - disables autostart
this.callBase(); this.callBase();
}, },
translateItems: function(num){ translateItems: function(num){
return (num === 1) ? "item" : "items"; return (num === 1) ? "item" : "items";
}, },
selectedClass: function (expected, current) { selectedClass: function (expected, current) {
return expected == current ? "selected" : ""; return expected == current ? "selected" : "";
} }
}); });
}); });
\ No newline at end of file \ No newline at end of file
define(["js/data/Collection", "app/model/Todo", "flow"], function (Collection, Todo, flow) { define(["js/data/Collection", "app/model/Todo", "flow"], function (Collection, Todo, flow) {
return Collection.inherit("app.collection.TodoList", { return Collection.inherit("app.collection.TodoList", {
$modelFactory: Todo, $modelFactory: Todo,
markAll: function (done) { markAll: function (done) {
this.each(function (todo) { this.each(function (todo) {
todo.setCompleted(done); todo.setCompleted(done);
todo.save(); todo.save();
}); });
}, },
areAllComplete: function () { areAllComplete: function () {
if (this.$items.length === 0) { if (this.$items.length === 0) {
return false; return false;
} }
for (var i = 0; i < this.$items.length; i++) { for (var i = 0; i < this.$items.length; i++) {
if (!this.$items[i].isCompleted()) { if (!this.$items[i].isCompleted()) {
return false; return false;
} }
} }
return true; return true;
}.on('change', 'add', 'remove'), }.on('change', 'add', 'remove'),
clearCompleted: function () { clearCompleted: function () {
var self = this; var self = this;
// remove all completed todos in a sequence // remove all completed todos in a sequence
flow().seqEach(this.$items,function (todo, cb) { flow().seqEach(this.$items,function (todo, cb) {
if (todo.isCompleted()) { if (todo.isCompleted()) {
// remove the todo // remove the todo
todo.remove(null, function (err) { todo.remove(null, function (err) {
if (!err) { if (!err) {
self.remove(todo); self.remove(todo);
} }
cb(err); cb(err);
}); });
} else { } else {
cb(); cb();
} }
}).exec(); }).exec();
}, },
numOpenTodos: function () { numOpenTodos: function () {
var num = 0; var num = 0;
for (var i = 0; i < this.$items.length; i++) { for (var i = 0; i < this.$items.length; i++) {
if (!this.$items[i].isCompleted()) { if (!this.$items[i].isCompleted()) {
num++; num++;
} }
} }
return num; return num;
}.on('change', 'add', 'remove'), }.on('change', 'add', 'remove'),
numCompletedTodos: function () { numCompletedTodos: function () {
var num = 0; var num = 0;
for (var i = 0; i < this.$items.length; i++) { for (var i = 0; i < this.$items.length; i++) {
if (this.$items[i].isCompleted()) { if (this.$items[i].isCompleted()) {
num++; num++;
} }
} }
return num; return num;
}.on('change', 'add', 'remove'), }.on('change', 'add', 'remove'),
hasCompletedTodos: function () { hasCompletedTodos: function () {
return this.numCompletedTodos() > 0; return this.numCompletedTodos() > 0;
}.on('change', 'add', 'remove') }.on('change', 'add', 'remove')
}); });
}); });
\ No newline at end of file
define(["js/data/Model"], function (Model) { define(["js/data/Model"], function (Model) {
return Model.inherit("app.model.Todo", { return Model.inherit("app.model.Todo", {
defaults: { defaults: {
title: "", title: "",
completed: false completed: false
}, },
setCompleted: function (completed) { setCompleted: function (completed) {
this.set("completed", completed); this.set("completed", completed);
}, },
isCompleted: function () { isCompleted: function () {
return this.$.completed; return this.$.completed;
}, },
status: function () { status: function () {
return this.$.completed ? "completed" : ''; return this.$.completed ? "completed" : '';
}.onChange("completed"), }.onChange("completed"),
hasTitle: function () { hasTitle: function () {
return this.$.title.trim().length; return this.$.title.trim().length;
}.onChange("title") }.onChange("title")
}); });
}); });
\ No newline at end of file
<ui:View xmlns="http://www.w3.org/1999/xhtml" <ui:View xmlns="http://www.w3.org/1999/xhtml"
xmlns:js="js.core" xmlns:ui="js.ui" componentClass="{todo.status()}"> xmlns:js="js.core" xmlns:ui="js.ui" componentClass="{todo.status()}">
<js:Script> <js:Script>
<![CDATA[ <![CDATA[
(function () { (function () {
var ENTER_KEY = 13; var ENTER_KEY = 13;
var INPUT_BLUR = "blur"; var INPUT_BLUR = "blur";
return { return {
defaults: { defaults: {
editing: false editing: false
}, },
$classAttributes: ['todo', 'inputElement'], $classAttributes: ['todo', 'inputElement'],
events: ["remove"], events: ["remove"],
editTodo: function (e) { editTodo: function (e) {
this.set("editing", true); this.set("editing", true);
e.preventDefault(); e.preventDefault();
this.$.inputElement.$el.select(); this.$.inputElement.$el.select();
return false; return false;
}, },
checkTodo: function () { checkTodo: function () {
var todo = this.get("todo"); var todo = this.get("todo");
todo.setCompleted(!todo.isCompleted()); todo.setCompleted(!todo.isCompleted());
todo.save(); todo.save();
}, },
preventEditing: function(e){ preventEditing: function(e){
e.stopPropagation(); e.stopPropagation();
}, },
updateTodo: function (e) { updateTodo: function (e) {
var todo; var todo;
if (e.domEvent.keyCode === ENTER_KEY || e.domEvent.type === INPUT_BLUR) { if (e.domEvent.keyCode === ENTER_KEY || e.domEvent.type === INPUT_BLUR) {
todo = this.get("todo"); todo = this.get("todo");
if (!todo.hasTitle()) { if (!todo.hasTitle()) {
this.trigger("remove", todo); this.trigger("remove", todo);
} else { } else {
this.set("editing", false); this.set("editing", false);
todo.save(); todo.save();
} }
} }
}, },
triggerOnRemove: function () { triggerOnRemove: function () {
this.trigger("remove", this.get("todo")); this.trigger("remove", this.get("todo"));
}, },
_renderEditing: function (editing) { _renderEditing: function (editing) {
if (editing) { if (editing) {
this.addClass("editing"); this.addClass("editing");
} else { } else {
this.removeClass("editing"); this.removeClass("editing");
this.$.inputElement.$el.blur(); this.$.inputElement.$el.blur();
} }
}, },
trim: function(title){ trim: function(title){
if(title){ if(title){
return title.trim(); return title.trim();
} }
return ""; return "";
} }
} }
}) })
]]> ]]>
</js:Script> </js:Script>
<js:Template name="layout"> <js:Template name="layout">
<div class="view" ondblclick="editTodo"> <div class="view" ondblclick="editTodo">
<input class="toggle" type="checkbox" onclick="checkTodo" ondblclick="preventEditing" <input class="toggle" type="checkbox" onclick="checkTodo" ondblclick="preventEditing"
checked="{todo.completed}"/> checked="{todo.completed}"/>
<label>{todo.title}</label> <label>{todo.title}</label>
<button class="destroy" onclick="triggerOnRemove"/> <button class="destroy" onclick="triggerOnRemove"/>
</div> </div>
<input class="edit" cid="inputElement" type="text" value="{{todo.title|trim()}}" <input class="edit" cid="inputElement" type="text" value="{{todo.title|trim()}}"
onkeyup="updateTodo" onblur="updateTodo" updateOnEvent="change"/> onkeyup="updateTodo" onblur="updateTodo" updateOnEvent="change"/>
</js:Template> </js:Template>
</ui:View> </ui:View>
{ {
"xamlClasses": ["app/Todo", "app/view/TodoView", "js/ui/ButtonGroup", "js/ui/Link", "js/ui/List", "js/ui/MenuButton", "js/ui/Modal", "js/ui/ScrollView", "js/ui/SplitButton", "js/ui/TabView"], "xamlClasses": [
"namespaceMap": null, "app/Todo",
"rewriteMap": null, "app/view/TodoView",
"paths": { "js/ui/ButtonGroup",
"xaml": "js/plugins/xaml", "js/ui/Link",
"json": "js/plugins/json", "js/ui/List",
"raw": "js/plugins/raw", "js/ui/MenuButton",
"flow": "js/lib/flow", "js/ui/Modal",
"inherit": "js/lib/inherit", "js/ui/ScrollView",
"underscore": "js/lib/underscore", "js/ui/SplitButton",
"JSON": "js/lib/json2.js" "js/ui/TabView"
}, "shim": { ],
"inherit": { "namespaceMap": null,
"exports": "inherit" "rewriteMap": null,
}, "paths": {
"flow": { "xaml": "js/plugins/xaml",
"exports": "flow" "json": "js/plugins/json",
}, "raw": "js/plugins/raw",
"underscore": { "flow": "js/lib/flow",
"exports": "_" "inherit": "js/lib/inherit",
}, "underscore": "js/lib/underscore",
"js/lib/parser": { "JSON": "js/lib/json2.js"
"exports": "parser" },
}, "shim": {
"JSON": { "inherit": {
"exports": "JSON" "exports": "inherit"
} },
}} "flow": {
\ No newline at end of file "exports": "flow"
},
"underscore": {
"exports": "_"
},
"js/lib/parser": {
"exports": "parser"
},
"JSON": {
"exports": "JSON"
}
}
}
\ No newline at end of file
.hide { .hide {
display: none; display: none;
} }
\ No newline at end of file
<!DOCTYPE HTML> <!doctype html>
<html> <html lang="en">
<head> <head>
<title>TodoMVC build with rAppid.js</title> <meta charset="utf-8">
<meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>rAppid.js • TodoMVC</title>
<link rel="stylesheet" href="../../../assets/base.css"> <link rel="stylesheet" href="../../../assets/base.css">
<!-- CSS overrides - remove if you don't need it --> <link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/app.css"> <!--[if IE]>
<!--[if IE]> <script src="../../../assets/ie.js"></script>
<script src="../../../assets/ie.js"></script> <![endif]-->
<![endif]--> <script src="app/lib/rappidjs.min.js"></script>
<script type="text/javascript" src="package/rappidjs.min.js"></script> <script>
<script type="text/javascript"> rAppid.bootStrap( 'app/Todo.xml', 'config.json', function ( err, systemManager, application ) {
rAppid.bootStrap("app/Todo.xml", "config.json", if ( !err ) {
function (err, systemManager, application) { application.start( null, function() {
if (!err) { application.render( document.body );
application.start(null, function () { });
application.render(document.body); } else {
}); console.warn( err );
} else { }
console.warn(err); });
} </script>
});
</script>
</head> </head>
<body></body>
</html> </html>
\ No newline at end of file
# Simple Todo App build with rAppid.js # rAppid.js TodoMVC app
> rAppid.js is a declarative JavaScript web application for rapid web application development. It uses XML to define the structure of applications, modules, components and views and JavaScript for the business logic of the application. The XML (xaml) gets translated to javascript components during runtime which will render itself as HTML5 DOM elements. This enables a rapid development of applications.
This example app demonstrates the features and abilities of [rAppid.js](http://www.rappidjs.com)
This example app demonstrates the features and abilities of rAppid.js
## Documentation ## Documentation
### The index.html ### index.html
In the index.html the app is bootstrapped by defining our main app file (in this case Todo.xml). Because rAppid.js is a RIA framework, the whole rendering is done by JavaScript.
In the index.html the application is bootStrapped by defining our main application file If you are now thinking "yeah fine, but what about SEO", don't worry, rAppid.js also support Node-Rendering, which can be used for things like SEO.
(in this case Todo.xml). Because rAppid.js is a RIA framework, the whole rendering is done by javascript.
If you are now thinking 'yeah fine, but what about SEO ', don't worry, rAppid.js also support Node-Rendering, which can be used for things like SEO.
### The application file Todo.xml ### Todo.xml
The main view of the application is declarated in Todo.xml. The first tag of the Todo.xml defines the super class of our application and the namespaces used inside the application description. The main view of the app is declarated in Todo.xml. The first tag of the Todo.xml defines the super class of our app and the namespaces used inside the app description.
```xml ```xml
<?xml version="1.0"?> <?xml version="1.0"?>
<app:TodoClass xmlns="http://www.w3.org/1999/xhtml" <app:TodoClass xmlns="http://www.w3.org/1999/xhtml" xmlns:js="js.core" xmlns:ui="js.ui" xmlns:app="app" xmlns:view="app.view" xmlns:conf="js.conf">
xmlns:js="js.core" xmlns:ui="js.ui" xmlns:app="app" xmlns:view="app.view" xmlns:conf="js.conf"> ...
...
</app:TodoClass> </app:TodoClass>
``` ```
As you can see, the default namespace is `"http://www.w3.org/1999/xhtml"` which allows us to use plain HTML elements to describe our view.
The other namespaces are used for custom components. As you can see, the default namespace is `"http://www.w3.org/1999/xhtml"` which allows us to use plain HTML elements to describe our view. The other namespaces are used for custom components.
One example of a custom component is the Router configuration. One example of a custom component is the Router configuration.
```xml ```xml
<js:Router cid="router"> <js:Router cid="router">
<conf:Route name="default" route="^$" onexec="showAll"/> <conf:Route name="default" route="^$" onexec="showAll"/>
<conf:Route name="active" route="^active$" onexec="showActive"/> <conf:Route name="active" route="^active$" onexec="showActive"/>
<conf:Route name="completed" route="^completed$" onexec="showCompleted"/> <conf:Route name="completed" route="^completed$" onexec="showCompleted"/>
</js:Router> </js:Router>
``` ```
Inside this declaration all routes of the application are defined. The **route** attribute expects a regular expression, which matches the route.
The **onexec** attribute defines the function which will be called, if the route is triggered.
The rest of the markup defines the UI of our application. All routes of the app are defined inside this declaration. The **route** attribute expects a regular expression, which matches the route. The **onexec** attribute defines the function which will be called, if the route is triggered.
To connect the view with our application model we use bindings. For example the header:
The rest of the markup defines the UI of our app. To connect the view with our app model we use bindings. For example the header:
```html ```html
<header id="header"> <header id="header">
<h1>{i18n.translate('title')}</h1> <h1>{i18n.translate('title')}</h1>
<input id="new-todo" placeholder="{i18n.translate('placeholder')}" type="text" onkeyup="addNewTodo" <input id="new-todo" placeholder="{i18n.translate('placeholder')}" onkeyup="addNewTodo" value="{{newTodo.title}}" autofocus="autofocus"/>
value="{{newTodo.title}}" autofocus="autofocus"/> </header>
</header>
``` ```
The bindings tell the application to hold view and model in sync. If you're interested in more details, checkout the rAppid.js wiki.
The bindings tell the app to hold view and model in sync. If you're interested in more details, checkout the [rAppid.js wiki](http://www.rappidjs.com/#/wiki/Home).
### TodoClass.js
### The code behind file TodoClass.js TodoClass.js is the code behind Todo.xml. It initializes the attributes used in this app and it defines the event handlers for routing and UI events. So there is a clean seperation between app code and UI declaration.
The TodoClass.js is the code behind file for Todo.xml. It initializes the attributes used in this application and it defines the event handlers for routing and ui events.
So there is a clean seperation between application code and ui declaration.
In the initialize method inside TodoClass all binded models are created and set as attributes of the application. This is important for resolving the bindings used in the view declaration. In the initialize method inside TodoClass all bound models are created and set as attributes of the app. This is important for resolving the bindings used in the view declaration.
### The Todo Model (app/model/Todo.js) ### Todo Model (app/model/Todo.js)
The default attributes for an instance and some methods used inside the app are defined in this model.
In this model, the default attributes for an instance and some methods used inside the application are defined.
It also marks the functions `hasTitle` and `status` as bindable. It also marks the functions `hasTitle` and `status` as bindable.
```javascript ```javascript
status: function () { status: function() {
return this.$.completed ? "done" : ''; return this.$.completed ? 'completed' : '';
}.onChange("completed"), }.onChange('completed'),
``` ```
Calling the `onChange(...)` function tells the application that the binding value of this methods has to be refreshed everytime the attributes change. Calling the `onChange()` function tells the app that the binding value of this methods has to be refreshed every time the attributes change. See app/view/TodoView.xml for usage.
See app/view/TodoView.xml for usage.
### Todo List (app/collection/TodoList.js)
### The Todo List (app/collection/TodoList.js)
The Todo List is a bindable List which encapsulates some app logic for manipulating the todo instances. It also declares bindable functions, which are used inside the view.
The Todo List is a bindable List which encapsulates some application logic for manipulating the todo instances.
It also declares bindable functions, which are used inside the view ...
### Todo View (app/view/TodoView.xml)
### The Todo View (app/view/TodoView.xml)
The Todo view is a custom view for displaying and editing Todo instances. The Todo view is a custom view for displaying and editing Todo instances. Here we define view logic and view declaration in one file.
Here we define view logic and view declaration in one file. \ No newline at end of file
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