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

rAppid.js app clenup and improve readme

parent 89083b70
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();
}, },
/** /**
...@@ -89,4 +94,4 @@ define(["js/core/Application", "js/core/I18n", "app/model/Todo", "app/collection ...@@ -89,4 +94,4 @@ define(["js/core/Application", "js/core/I18n", "app/model/Todo", "app/collection
return expected == current ? "selected" : ""; return expected == current ? "selected" : "";
} }
}); });
}); });
\ No newline at end of file \ No newline at end of file
{ {
"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": [
"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"
],
"namespaceMap": null, "namespaceMap": null,
"rewriteMap": null, "rewriteMap": null,
"paths": { "paths": {
...@@ -10,7 +21,8 @@ ...@@ -10,7 +21,8 @@
"inherit": "js/lib/inherit", "inherit": "js/lib/inherit",
"underscore": "js/lib/underscore", "underscore": "js/lib/underscore",
"JSON": "js/lib/json2.js" "JSON": "js/lib/json2.js"
}, "shim": { },
"shim": {
"inherit": { "inherit": {
"exports": "inherit" "exports": "inherit"
}, },
...@@ -26,4 +38,5 @@ ...@@ -26,4 +38,5 @@
"JSON": { "JSON": {
"exports": "JSON" "exports": "JSON"
} }
}} }
\ No newline at end of file }
\ 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 type="text/javascript" src="package/rappidjs.min.js"></script> <script src="app/lib/rappidjs.min.js"></script>
<script type="text/javascript"> <script>
rAppid.bootStrap("app/Todo.xml", "config.json", rAppid.bootStrap( 'app/Todo.xml', 'config.json', function ( err, systemManager, application ) {
function (err, systemManager, application) { if ( !err ) {
if (!err) { application.start( null, function() {
application.start(null, function () { application.render( document.body );
application.render(document.body);
}); });
} else { } else {
console.warn(err); 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 application is bootStrapped by defining our main application file 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 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. 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
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. ### Todo.xml
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).
### The code behind file TodoClass.js
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. ### 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 Todo Model (app/model/Todo.js) 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.
In this model, the default attributes for an instance and some methods used inside the application are defined.
### Todo Model (app/model/Todo.js)
The default attributes for an instance and some methods used inside the app are defined in this model.
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.
### The Todo List (app/collection/TodoList.js)
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 ...
### The Todo View (app/view/TodoView.xml)
The Todo view is a custom view for displaying and editing Todo instances.
Here we define view logic and view declaration in one file.
### 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.
### Todo View (app/view/TodoView.xml)
The Todo view is a custom view for displaying and editing Todo instances. 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