【问题标题】:Falcor - 'get' no longer emits references as leaf valuesFalcor - 'get' 不再将引用作为叶值发出
【发布时间】:2019-06-03 16:50:09
【问题描述】:

我最近从 Falcor 0.x 升级到 1.1.0(下一步将是 2.x)

根据Falcor migration documentation,在调用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 引用?

【问题讨论】:

    标签: falcor falcor-router


    【解决方案1】:

    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 只能包含多个相同深度的路径。所以不同深度的多条路径只能用多个pathSet来表示。

    【讨论】:

    • 谢谢!我有一个更复杂的用例,其中包含一个 cmets(范围)列表,但经过一些调整后就成功了
    猜你喜欢
    • 2017-06-22
    • 2023-03-29
    • 2016-01-12
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    相关资源
    最近更新 更多