修改了这个问题以更好地解释:
我有两个来自两个不同HttpDataSource的Falcor模型,如下所示:
第一种模式(用户模式):
const user_model = new falcor.Model(
{
source: new HttpDataSource('http://localhost:3000/api/userManagement')
});
user_model.get(['user', 'list'])
OUTPUT1:
{
"jsonGraph": {
"user": {
"list": {
"$type": "atom",
"value": {
"users": [...]
}
}
}
}
}
第二个模式(榜样):
const role_model = new falcor.Model(
{
source: new HttpDataSource('http://localhost:3000/api/roleManagement')
});
role_model.get(['role', 'list'])
OUTPUT2:
{
"jsonGraph": {
"role": {
"list": {
"$type": "atom",
"value": {
"roles": [...]
}
}
}
}
}
有没有办法将所有这些Falcor模型组合成一个单一的模型?
其目的是,如果我多次尝试执行user_model.get(“用户”、“列表”),它将从Falcor-Model-Cache (在第一次从DB获取数据之后)获取数据。
但是,如果我尝试执行role_model.get(' User ',' list '),那么我必须再次访问DB以获取数据(以便将相同的用户列表存储在role_model缓存中)。
因此,如果有如下所示的方法:
all_model = user_model + role_model
然后我可以做all_model.get(‘用户’,‘列表’)(或)all_model.get(‘角色’,‘列表’)。因此,基本上我只能在浏览器端有一个合并的Falcor-Model-Cache。
希望这个问题现在更清楚了。
发布于 2018-03-19 23:43:12
您必须使用forkJoin
forkJoin(model1.source,model2.source).subscribe(res=>{
//in res[0] you have the response of model1.source
//in res[1] you have the response of model2.source
let data={...res[0],...res[1]}
//in data you have all the properties
}
https://stackoverflow.com/questions/49378519
复制相似问题