JavaScript的MVC框架:Derby.js

jopen 11年前

一个MVC框架,可以很容易地编写实时协作可在Node.js和浏览器中运行的应用程序。

hello.js
var app = require('derby').createApp(module);    // Add template for rendering HTML and model <- -> view bindings  app.view.make('Body',    'Holler: <input value="{hello.message}"><h1>{hello.message}</h1>'  );    // Add a route, which can render in the browser as well as server  app.get('/', function(page, model) {    // Specify data to sync    model.subscribe('hello.message', function() {      page.render();    });  });

server.js
var store = require('derby').createStore({    // Use the mongo adapter to persist data and perform queries    db: require('livedb-mongo')('localhost:27017/test?auto_reconnect')    // Keep a journal of all data changes and do PubSub with Redis  , redis: require('redis').createClient()  });    var expressApp = require('express')()    // Add browserchannel scripts to bundles created by store, and    // return middleware for responding to remote client messages    .use(require('racer-browserchannel')(store))    // Respond to requests for application script bundles    .use(app.scripts(store))    // Create models for incoming requests    .use(store.modelMiddleware())    // Add the app's routes    .use(app.router())    require('http').createServer(expressApp).listen(3000);

项目主页:http://www.open-open.com/lib/view/home/1384219278227