Package Exports
- webtasks
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (webtasks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
webtasks
A lightweight web framework based on express and subtask.js
Features
Make developer decouple complex web application logic into small logic pieces for reusing, and speed up implement and testing.
- All logical components are webtasks in commonjs.
- All webtask are async.
Logical components in this framework
- Input: focus on deal with params or other request based inputs
- Data: call api or get data from storage
- Module: handle presentation logics then rendered with a view
- Page: composite modules then rendered with a view
Getting Started
Create your app
npm init
npm install webtasks --saveHello World
- Create a page webtask in
page/hello.js:
/*jslint node: true */
'use strict';
module.exports = function () {
return this.task({
title: 'Good!',
description: 'Hello World'
});
};- Create a handlebars.js view for
page/hello.jsinview/page_hello.hbs:
<html>
<head>
<title>{{title}}</title>
</head>
<body>
{{description}}
</body>
</html>- Create an express server in
server.js:
/*jslint node: true */
'use strict';
var app = require('webtasks');
app
.use(app.middleware('page', 'hello'))
.listen(3000);- Start the server and browse http://localhost:3000/ :
node server.jsAbout Webtask
Webtask is extended from subtask with Context API . Webtasks are automatic singleton per-request, developers do not need to worry about api optimization or task sequence.
For example, to deliver a article page for login user brings this task depdency:
[checkLogin] -> [getArticle] -> [setPageTitle] -> [composeModules]If we add another module depend on another data source, then the module tasks will be appended after composeModules and make the task queue longer. When we try to speed up html deliver time, we will mess up the module composite tasks and data tasks.
When this done by webtasks it will like:
// NOTE: pseudo code
articlePage = webtask({
isLogin: input('isLogin'),
title: param('id').pipe(data('getArticle')).pick('title'), // one data('getArticle')
story: param('id').pipe(module('article')),
});
articleModule = param('id').pipe(data('getArticle')); // another data('getArticle')
dataGetArticle = function (id) {
return webtask( ..... call API by id );
};All data('getArticle') with same id in this request refer to single webtask instance, the API call will be executed only one time in a request. Another good news is all webtask/subtask are executed parallel, you get performance boost. And, all webtasks focus on handle jobs for itself, you do not need to add extra code to maintain states cross different modules.
Page Component
Page is a webtask which will be rendered by a handlebars.js temlpate view. All pages are placed under page directory, and all views for pages are placed under view directory with page_* prefix.
Module Component
Module is a webtask which will be rendered by a handlebars.js temlpate view. All modules are placed under module directory, and all views for pages are placed under view directory with module_* prefix. The behavior of a module or a page are exact same, they are named differently for concept reason.
Data Component
Data is a webtask without view and focus on get and processs data. All data are placed under data directory.
Input Component
Input is a webtask without view and focus on get and process inputs from request, all inputs are places under input directory. The behavior of a input or a data are exact same, they are named differently for concept reason.
AJAX Component
AJAX is a webtask without view and focus on response json by different request. Actually AJAX is normal webtask placed under ajax directory, and in most case it will execute input and data subtasks.
REACT Component
REACT is pure jsx commonjs module be placed under react directory. You can pipe data into react component to render static or dynamic modules, please check the Context API: this.react and this.dreact .
Context API
this.paramthis.headerthis.cookiethis.pagethis.modulethis.datathis.inputthis.reactthis.dreact
TODO
- sample project
- react state ajax bridge
- flux?
- css component
- gulp env