Derby 是一个 Javascrript 的MVC 框架,帮助编写实时,交互的应用。可以运行在 Node.js 或者浏览器环境中。
示例代码:
Hello.js
var hello = require('derby').createApp(module)
, vIEw = hello.view
, get = hello.get;
// Templates define both HTML and model <- -> view BINDings
view.Make('Body'
, 'Holler: <input value="{message}"><h1>{message}</h1>'
);
// Routes render on client as well as server
get('/', Function (page, model) {
// Subscribe SPEcifies the Data to sync
model.subscribe('message', function () {
page.render();
});
});
server.js
var Express = require('express')
, expressApp = express()
, server = require('HTTP').createServer(expressApp);
// The server-side sTore syncs data over Socket.IO
var store = require('derby').createStore({listen: server});
expressApp
.use(express.static(__dirname + '/public'))
// The store creates models for incoming Requests
.use(store.modElmiddleware())
// App routes create an Express middleware
.use(require('./hello').router());
server.listen(3000);
发布于 2014-08-25 23:52:24 | 164 次阅读