法尔克
这是 图形学 falcorJS客户端库分叉. 这个库包括一些bug修正,性能改进,以及附加功能,并将被积极维护和开发.
该项目与Netflix/虚假的区别
- 关键bugs已经修复.
- 核心
get算法改进了~100%. getVersion运行时间到了O(1)。 。 。 .- 在可能的情况下,在Netflix/falcor基准中增加了性能测试.
- 可选
branchSelector已经引入,允许用户自定义来自get打电话. - 可选
recycleJSON已启用了旗帜, 指示该模型将输出的 JSON 对象移出并循环使用get打电话 这使得我们能够显著地改进稳定的查询的性能(见get业绩数字(见下文). - 一个
onChangesCompletedaPI中已添加回调 。 这种回调类似于现有的onChange调回调用,但只有在所有将更改缓存的操作完成后才调用(这比去除onChange(原始内容存档于2017-03-21). callback. falcor-http-datasource已经从公共浏览器构建中删除.- 路径语法已被删除 。 要使用路径语法, 您可以使用 @graphistry/falcor-path-语法 模块将字符串分解为路径。 最好还是用新的 查询语法 模板字符串.
路线图
- 应用
get改进set。 。 。 . - 内部代码清理以减少锅炉板并存档.
业绩比较
Get Tests:
@netflix/falcor getJSON - 100 paths from cache x 13,715 ops/sec ±16.34% (70 runs sampled) (0.42% of 1 frame @ 60FPS)
@graphistry/falcor getJSON - 100 paths from cache x 26,009 ops/sec ±3.15% (75 runs sampled) (0.24% of 1 frame @ 60FPS)
@graphistry/falcor getJSON - 100 paths from cache x 3,100,760 ops/sec ±10.00% (78 runs sampled) (0% of 1 frame @ 60FPS) (recycled JSON)
@netflix/falcor getJSONGraph - 100 paths from cache x 2,920 ops/sec ±2.10% (85 runs sampled) (2.04% of 1 frame @ 60FPS)
@graphistry/falcor getJSONGraph - 100 paths from cache x 2,516 ops/sec ±11.44% (67 runs sampled) (2.4% of 1 frame @ 60FPS)
@netflix/falcor getVersion x 2,178,625 ops/sec ±6.18% (70 runs sampled) (0% of 1 frame @ 60FPS)
@graphistry/falcor getVersion x 5,019,760 ops/sec ±5.46% (78 runs sampled) (0% of 1 frame @ 60FPS)
Set Tests:
@netflix/falcor setJSONGraph - 100 paths into cache x 5,800 ops/sec ±11.90% (77 runs sampled) (1.02% of 1 frame @ 60FPS)
@graphistry/falcor setJSONGraph - 100 paths into cache x 4,987 ops/sec ±10.68% (75 runs sampled) (1.2% of 1 frame @ 60FPS)
@netflix/falcor setPathMaps - 100 paths into cache x 4,331 ops/sec ±1.67% (80 runs sampled) (1.38% of 1 frame @ 60FPS)
@graphistry/falcor setPathMaps - 100 paths into cache x 3,852 ops/sec ±6.05% (76 runs sampled) (1.56% of 1 frame @ 60FPS)
@netflix/falcor setPathValues - 100 paths into cache x 2,354 ops/sec ±12.83% (68 runs sampled) (2.52% of 1 frame @ 60FPS)
@graphistry/falcor setPathValues - 100 paths into cache x 2,441 ops/sec ±9.82% (68 runs sampled) (2.46% of 1 frame @ 60FPS)
DataSource Tests:
@netflix/falcor getJSON - 50 of 100 paths from DataSource x 1,100 ops/sec ±2.03% (81 runs sampled) (5.46% of 1 frame @ 60FPS)
@graphistry/falcor getJSON - 50 of 100 paths from DataSource x 1,557 ops/sec ±6.89% (73 runs sampled) (3.84% of 1 frame @ 60FPS)
@graphistry/falcor getJSON - 50 of 100 paths from DataSource x 47,791 ops/sec ±7.21% (78 runs sampled) (0.12% of 1 frame @ 60FPS) (recycled JSON)
@netflix/falcor getJSONGraph - 50 of 100 paths from DataSource x 635 ops/sec ±8.75% (79 runs sampled) (9.42% of 1 frame @ 60FPS)
@graphistry/falcor getJSONGraph - 50 of 100 paths from DataSource x 614 ops/sec ±6.47% (73 runs sampled) (9.78% of 1 frame @ 60FPS)
开始
您可以检查 Netflix 类似应用程序的工作示例服务器 这里 现在 换句话说,你可以通过这个赤骨教程,其中我们使用Falcor路由器创建虚拟JSON资源. 在此教程中,我们将使用 Falcor 的快取中件,在 URL /model.json 的应用程序服务器上服务 Virtual JSON 资源. 我们还将在同一个服务器上主持一个静态网页,从Virtual JSON资源取回数据.
创建虚拟 JSON 资源
在这个例子中,我们将使用falcor路由器在应用程序服务器上构建一个虚拟JSON资源,并在/model.json上主机. JSON资源将包含以下内容:
{
"greeting": "Hello World"
}
通常路由器会从后端数据库或其他网络服务点取其Virtual JSON资源的数据. 然而,在这个简单的教程中,路由器会简单地返回单个密钥的静态数据.
首先,我们为应用程序服务器创建文件夹 .
mkdir falcor-app-server
cd falcor-app-server
npm init
现在我们安装了Falcor路由器.
npm install falcor-router --save
然后安装快活和活佛快活 此外,还提供恢复支助,以及通过a/ 第三方实施。 。 。 .
npm install express --save
npm install falcor-express --save
现在我们创建了索引.js文件,其内容如下:
// 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);
现在我们运行服务器, 它将在3000端口听 请求 /model.json.
node index.js
从虚拟 JSON 资源获取数据
现在,我们已经用单一的只读密钥"greeting"构建了一个简单的虚拟JSON文档,我们将创建一个测试网页并从服务器上取回这把密钥.
现在创建一个索引.html文件,其内容如下:
<!-- index.html -->
<html>
<head>
<!-- Do _not_ rely on this URL in production. Use only during development. -->
<script src="https://netflix.github.io/falcor/build/falcor.browser.js"></script>
<!-- For production use. -->
<!-- <script src="https://cdn.jsdelivr.net/falcor/{VERSION}/falcor.browser.min.js"></script> -->
<script>
var model = new falcor.Model({source: new falcor.HttpDataSource('/model.json') });
// retrieve the "greeting" key from the root of the Virtual JSON resource
model.
get("greeting").
then(function(response) {
document.write(response.json.greeting);
});
</script>
</head>
<body>
</body>
</html>
请访问http://localhost:30/index.html,请查看从服务器上检索到的信息:
哈罗世界
额外资源
详细介绍模型、路由器和JSON图表的高级别文件请检查 法尔克网站。 。 。 .
API 文档请访问 这里
对于路由器的示例,请查看 壁炉-路由-演示。 。 。 .
用于提问和讨论 叠叠流。 。 。 .