realm - Realm App Architecture with Full Sync - 如何在多领域架构中同步
问题描述
遵循 App Architecture Guidelines,我想在我的按需领域中保持一些公共数据同步。
举个简单的例子:
- 汽车为所有客户同步并存储在
/commonRealm
- 行程仅为相关用户同步并存储在
/~/driverRealm
下面是应用程序的最小架构
const CarSchema = {
name: 'Car',
primaryKey: 'id',
properties: {
id: {type: 'string'},
make: {type: 'string'},
model: {type: 'string'}
}
};
const TripSchema = {
name: 'Trip',
primaryKey: 'id',
properties: {
id: {type: 'string'},
name: {type: 'string'},
car: {type: 'Car'}
}
};
commonRealm 仅包含 CarSchema。driverReam 包括 CarSchema 和 TripSchema。驾驶员永远不会更新汽车,其目的实际上是为了查找。
我找不到如何让 Cars 在领域之间保持同步的示例,以便将 commonRealm 中的任何更新传播到驱动程序的 driverRealm。
使用 subscribe() 收听 commonRealm Cars 对象并没有帮助,因为您无法访问已删除的数据等。
从我可以从文档中推断出,这个架构实际上应该是这样的:
const CarSchema = {
name: 'Car',
primaryKey: 'id',
properties: {
id: {type: 'string'},
make: {type: 'string'},
model: {type: 'string'}
}
};
const TripSchema = {
name: 'Trip',
primaryKey: 'id',
properties: {
id: {type: 'string'},
name: {type: 'string'},
carId: {type: 'string'} // foreign key
}
};
commonRealm 将包含 CarSchema,而 driverReam 将仅包含带有 carId 的 TripSchema,作为 Car.id 的类型字符串,而不是 Car 的类型。由客户端运行地图/循环以从 commonRealm 手动加入 Car,例如:
let tripsWithCar = [];
trips.forEach(trip => {
trip.car = commonRealm.objects('Car').filtered(`id == "${trip.carId}"`)[0];
tripsWithCar.push(trip);
});
如果这是正确的方法,我想从有更多经验的开发人员那里获得一些反馈。
解决方案
推荐阅读
- r - 如何用数字子串动态字符(例如:$1000, 100units)
- excel - 使用 SSRS 2008 订阅电子邮件时 EXCEL 出现问题
- javascript - 尝试访问空的 JavaScript 数组而不出错
- c# - 小数大于 5 .net 时的问题
- c# - asp.net mvc 4数据未绑定
- python - 使用 python + asyncio + websockets 推送 = 丢失消息
- dhall - `dhall format` 和 `dhall lint` 之间的区别
- python-3.x - Pandas 根据值乘法生成行
- spring-webflux - spring-boot-starter-webflux 是否包含 spring-boot-starter-web?
- angular - 微前端,使用 Angular 框架作为外部