0

サーバーで次の Router クラスが実行されているとします。

var PetsRouterBase = Router.createClass([{
  route: 'petList[{integers:indices}].name',
  get: function(pathSet) {

    return [
      { 
        path: ['petList', 0, 'name'], 
        value: 'Pets I have now'
      },
      { 
        path: ['petList', 1, 'name'], 
        value: 'Pets I once had'
      },
      { 
        path: ['petList', 2, 'name'], 
        value: 'Pets my friends have'
      }
    ];
  }
}]);

そして、ブラウザーで次のパス クエリを実行します (私は falcor-http-datasource を使用しています)。

model.get('petList[0..2].name');

次の正しいデータを取得します。

{
  "jsonGraph": {
    "petList": { 
      "0":{"name":"Shows of Artists I've been to before",
      "1":{"name":"Shows of artists my friends have been to before",
      "2":{"name":"Highly rated artists"}
    }
  }
}

私の質問は、サーバー上で、この get route リクエストに応答して falcor がネットワーク経由でブラウザーに送信する実際の結果にアクセスする方法ですか?

私の使用例は、2 つのデータをまとめてログアウトすることです。

  1. ルートが渡される pathSet。
  2. falcor がネットワーク経由で送り返す json の結果。

私はそれが次のようになるかもしれないと思っていました:

var PetsRouterBase = Router.createClass([{
  route: 'petList[{integers:indices}].name',
  done: function(pathSet, results) {
    // Log out the result of the lookup
    console.log(pathSet, results); 
  },
  get: function(pathSet) {

    return [
      { 
        path: ['petList', 0, 'name'], 
        value: 'Pets I have now'
      },
      { 
        path: ['petList', 1, 'name'], 
        value: 'Pets I once had'
      },
      { 
        path: ['petList', 2, 'name'], 
        value: 'Pets my friends have'
      }
    ];
  }
}]);

ただ明確にします。クライアントで結果を取得できることはわかっていますが、サーバー上の別の場所にパイプしたいと考えています。

4

1 に答える 1

1

現時点で最も簡単なのは、Router をエクスプレス ミドルウェアに送信する前にデコレートすることです。

app.use('/model.json', FalcorServer.dataSourceRoute(function(req, res) {
    return {
        get: function(pathSets) {
            // print incoming paths to console
            console.log(JSON.stringify(pathSets, null, 4));
            return router.
                get(pathSets).
                // print the results to the console
                    doAction(function(output) {
                        console.log(JSON.stringify(output, null, 4));    
                    });
        }
    };
})
于 2015-08-20T11:41:02.813 に答える