[英]Falcor - 'get' no longer emits references as leaf values
我最近從Falcor 0.x升級到1.1.0(下一步將是2.x)
根據Falcor遷移文檔 ,在調用model.get
引用不再作為json發出。
但是,我想知道什么是在model.get
管理引用的最佳實踐。
這是一個例子。
具有以下json圖:
{
jsonGraph: {
comment: {
123: {
owner: { $type: "ref", value: ["user", "abc"] },
message: "Foo"
}
},
user: {
abc: {
name: "John Doe"
initials: "JD"
}
}
}
}
調用model.get
將導致:
const json = await model.get(["comment", "123", ["owner", "message"]);
{
owner: undefined, // 0.x was returning `["user", "abc"]`
message: "John Doe"
}
但是,可以僅獲得所有者:
const json = await model.get(["comment", "123", "owner", ["name", "initials"]);
{
name: "John Doe",
initials: "JD"
}
對在model.get
處理引用的建議是什么?
我應該手動獲取所有者(如上一個示例?),還是應該在comment
模型中使用ownerId
而不是owner
引用?
model.get
可以采用任意數量的pathSets
( docs )。 因此,將您的第一個pathSet
分成兩個並作為單獨的參數傳遞:
await model.get(
["comment", "123", "message"],
["comment", "123", "owner", ["name", "initials"]]
);
應該返回
{
message: "John Doe"
owner: {
name: "John Doe",
initials: "JD"
}
}
潛在的限制是,單個pathSet只能包含相同深度的多個路徑。 因此,不同深度的多個路徑只能由多個pathSets表示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.