[Farcol] Introduce

Use the Falcor Router to create a Virtual JSON resource. In this tutorial we will use Falcor’s express middleware to serve the Virtual JSON resource on an application server at the URL /model.json. We will also host a static web page on the same server which retrieves data from the Virtual JSON resource.

index.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(3030);

index.html:

<!-- index.html -->
<html>
<head>
    <!-- Do _not_  rely on this URL in production. Use only during development.  -->
    <script src="//netflix.github.io/falcor/build/falcor.browser.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>
时间: 2024-10-20 07:26:41

[Farcol] Introduce的相关文章

重构改善既有代码设计--重构手法05:Introduce Explaining Variable (引入解释性变量)

  发现:你有一个复杂的表达式. 解决:将该复杂的表达式(或其中的部分)的结果放进一个临时变量,并以此变量名称来解释表达式用途. //重构前 if((platform.toUpperCase().indexOf("MAC") > -1) && (browser.toUpperCase().indexOf("IE") > -1) && wasInitialized() && resize > 0) {

Backbone introduce

I had immersed in web developer more than one year. during this past year, I read a lot of books about fond-end. from css,javascript,jquery and html. especial books about javascript. Yes, Javascript one one lauguange which you perhaps love and hate t

重构改善既有代码设计--重构手法16:Introduce Foreign Method (引入外加函数)&amp;&amp; 重构手法17:Introduce Local Extension (引入本地扩展)

重构手法16:Introduce Foreign Method (引入外加函数)你需要为提供服务的类增加一个函数,但你无法修改这个类.在客户类中建立一个函数,并以第一参数形式传入一个服务类实例. 动机:这种事情发生了太多次了,你正在使用一个类,它真的很好,为你提供了需要的所有服务.而后,你又需要一项新服务,这个类却无法供应.于是你开始咒骂“为什么不能做这件事?”如果可以修改源码,你便可以自行添加一个新函数:如果不能,你就得在客户端编码,补足你要的那个函数. 如果客户类只使用这项功能一次,那么额外

Introduce Explaining Variable

[Introduce Explaining Variable] 引入解释性变量.

[教育]Singapore plans to introduce programming lessons in public schools to boost the economy

Singapore plans to introduce programming lessons in public schools to boost the economy Terence Lee2:38 pm on Jan 14, 2014 Follow @terenceleejx Update on January 15: Added a statement from IDA about its plans. The Infocomm Development Authority of Si

Introduce Null Object

[Introduce Null Object]

wood cnc router machine application industry and introduce

wood cnc router machine application industry and introduce Wood cnc router machine can be used to carving, engraving, cutting use. These three effects will depend on whether your woodworking engraving machine spindle motor power can reach it work loa

『重构--改善既有代码的设计』读书笔记----Introduce Explaning Variable

有时候你会遇到一系列复杂的表达式连续运算的时候,这个时候你可能根本招架不住如此长或者是如此复杂的长函数.这个时候你可以通过引用临时变量来储存他们的结果,将这些长函数的结果分成一个个临时变量来让函数清晰化.但在这里,我的想法与作者的想法是一样的,我会更倾向于去用Extract Method去将复杂函数弄清晰,而尽量不去Introduce Explaning Vaiable,因为Extract Method优点很多,除了不增加临时变量增加函数长度之外,他的生命周期也比临时变量来的长,他可以让类中的所

『重构--改善既有代码的设计』读书笔记----Introduce Local Extension

同Introduce Foreign Method一样,很多时候你不能修改编辑原始类,你需要为这些服务类增加一些额外的函数,但你没有这个权限或者入口.如果你只需要一个或者两个外加函数那么你可以放心的使用Introduce Foregin Method,但是如果你发现此时有很多外加函数需要在客户类代码中中添加,你就要小心了,因为你这么做你就会让客户类变得过分复杂,责任就会过分多,你会破坏客户类的单一职责性.这个时候你就可以建立一个新类,让他来包含这些你之前所添加的额外函数,让这个扩展类成为源类的子