簡體   English   中英

Falcor-'get'不再發出引用作為葉值

[英]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可以采用任意數量的pathSetsdocs )。 因此,將您的第一個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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM