2
나는 normalizr을 사용하고 있습니다. 나는 문자열을 정규화하려고 시도하지만 알아 내지 못했습니다. (잘못 때문에주의 conversationIdSchema
작동하지 않습니다) 나는이 같은 conversationIds을하도록 노력하겠습니다문자열을 정규화 할 수 있습니까?
{
result: { mails: ['mailId1', 'mailId2'] },
entities: {
users: {
'[email protected]': { name: 'Jack', address: '[email protected]' }
'[email protected]': { name: 'Rose', address: '[email protected]' }
},
mails: {
// ...
}
}
}
을 :
const mails = [
{
"id": "mailId1",
"conversationId": "conversationId1",
"content": "Hi",
"sender": {
"emailAddress": { name: 'Jack', address: '[email protected]' }
}
},
{
"id": "mailId2",
"conversationId": "conversationId1",
"content": "Hello",
"sender": {
"emailAddress": { name: 'Rose', address: '[email protected]' }
}
}
]
const userSchema = new schema.Entity('users', {}, {
idAttribute: value => value.emailAddress.address
});
const conversationIdSchema = new schema.Entity('conversationIds', {}, {
idAttribute: value => value
});
const mailSchema = new schema.Entity('mails', {
conversationId: conversationIdSchema,
sender: userSchema
});
const normalizedData = normalize(mails, [mailSchema]);
지금 위의 코드는 결과를 아래 나에게 줄 것이다
을{
result: { mails: ['mailId1', 'mailId2'] },
entities: {
users: {
'[email protected]': { name: 'Jack', address: '[email protected]' }
'[email protected]': { name: 'Rose', address: '[email protected]' }
},
mails: {
// ...
},
conversationIds: ['conversationId1']
}
}