Falcor高效從服務(wù)器返回?cái)?shù)據(jù)的 Javascript 庫(kù)
Falcor 是高效的 JavaScript 數(shù)據(jù)抓取庫(kù)。
一個(gè)模型隨處使用:通過(guò)一個(gè)虛擬 JSON 圖可以把所有遠(yuǎn)程數(shù)據(jù)源作為一個(gè)單獨(dú)的主模型
數(shù)據(jù)即是 API:類(lèi)似 JavaScript 路徑語(yǔ)法,可以很簡(jiǎn)單的訪問(wèn)數(shù)據(jù)。
綁定云:自動(dòng)遍歷圖里面的引用,根據(jù)需要進(jìn)行請(qǐng)求
代碼示例:
// index.js
var falcorExpress = require('falcor-express');
var Router = require('falcor-router');
var express = require('express');
var app = express();
app.use('/model.json', falcorExpress.dataSourceRoute(function (req, res) {
// create a Virtual JSON resource with single key ("greeting")
return new Router([
{
// match a request for the key "greeting"
route: "greeting",
// respond with a PathValue with the value of "Hello World."
get: function() {
return {path:["greeting"], value: "Hello World"};
}
}
]);
}));
// serve static files from current directory
app.use(express.static(__dirname + '/'));
var server = app.listen(3000);評(píng)論
圖片
表情
