如何使用normalizr分配与实体父级相关的id/slug ?
例:
用户调用的API响应:
{
id: '12345',
firstName: 'John',
images: [
{
url: 'https://www.domain.com/image0',
name: 'image0'
},
{
url: 'https://www.domain.com/image1',
name: 'image1'
}
]
}
Run Code Online (Sandbox Code Playgroud)
我可以通过以下方式定义我的模式:
const image = new Schema('images');
const user = new Schema('users');
user.define({
images: arrayOf(image)
})
Run Code Online (Sandbox Code Playgroud)
问题是图像没有id属性,因此除非我们提供id属性,否则normalizr将无法区分它们.当然,我们可以做点什么
const image = new Schema('images', { idAttribute: uuid.v4() });
Run Code Online (Sandbox Code Playgroud)
并生成唯一标识符.
假设我们收到用户更新,并且图像名称已更新.因为我们在每个规范化中生成唯一标识符,所以我们无法识别和更新现有图像.
我需要一种方法来引用图像实体中的父实体(用户)(在其id/slug中12345-image0,12345-image1或作为单独的属性).
实现这一目标的最佳方法是什么?
有没有什么办法可以在 iOS 应用程序在后台时使用 Google Nearby Messages API 发布消息?
根据 Nearby Messages API文档:
只要发布对象存在,发布就处于活动状态。要停止发布,请释放发布对象。
我没有释放发布对象,但应用程序似乎在后台运行时停止发布消息(尽管我已打开 BLE 和音频背景模式)。
bluetooth ios core-bluetooth bluetooth-lowenergy google-nearby