问题描述
我最近已从Falcor 0.x升级到1.1.0(下一步将是2.x)
I've recently upgraded from Falcor 0.x to 1.1.0 (2.x will be the next step)
根据 Falcor迁移文档,当调用model.get
引用时,不再将其作为json发出.
According to the Falcor migration documentation, when calling model.get
references are not emitted as json anymore.
但是,我想知道在model.get
中管理引用的最佳实践是什么.
I'm however wondering what would be the best practice in order to manage references in a model.get
.
这里是一个例子.
具有以下json图:
Having the following json graph:
{
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"
}
但是有可能仅获得所有者:
However it's possible to get the owner only:
const json = await model.get(["comment", "123", "owner", ["name", "initials"]);
{
name: "John Doe",
initials: "JD"
}
在model.get
中处理引用的建议是什么?
What is the recommendation for handling references in model.get
?
我应该手动获取所有者(如上一个示例吗?)还是应该在comment
模型中使用ownerId
而不是owner
引用?
Should I manually get the owner (like the last example?) or should I have an ownerId
instead of an owner
reference in comment
model?
推荐答案
model.get
可以采用任意数量的pathSets
(文档).因此,将您的第一个pathSet
分为两个并作为单独的参数传递:
model.get
can take any number of pathSets
(docs). So, break your first pathSet
into two and pass as separate arguments:
await model.get(
["comment", "123", "message"],
["comment", "123", "owner", ["name", "initials"]]
);
应该返回
{
message: "John Doe"
owner: {
name: "John Doe",
initials: "JD"
}
}
基本约束是,单个pathSet只能包含相同深度的多个路径.因此,不同深度的多个路径只能由多个pathSets表示.
The underlying constraint is that a single pathSet can only include multiple paths of the same depth. So multiple paths of different depth can only be represented by multiple pathSets.
这篇关于Falcor-'get'不再发出引用作为叶值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!