2017-01-19 1 views
0

표준화 버전 3.1.x로 업데이트되었으므로 표준화를 활용할 수 있습니다. 그들은 API를 크게 변경했습니다. 내 스키마를 전송하는 데 문제가 있습니다.Normalizr v2에서 v3으로 스키마를 변환하는 데 문제가 있습니다.

import { normalize, Schema, arrayOf, valuesOf } from 'normalizr'; 

const usersSchema = new Schema('users') 
const photosSchema = new Schema('photos') 
const phonesSchema = new Schema('phones') 

photosSchema.define({ 
    users: arrayOf(usersSchema) 
}) 

phonesSchema.define({ 
    users: arrayOf(usersSchema) 
}) 

usersSchema.define({ 
    photos: valuesOf(photosSchema), 
    phones: valuesOf(phonesSchema) 
}) 

이것은 내 기존 스키마입니다. 나는 또한 내 REDUX 액션 내부의 redux-normalizr middleware을 사용하고 있었다, 그래서 나는 이런 나의 행동에 스키마를 연결 :

import { usersSchema } from '../normalizrSchemas/usersSchemas.js' 
import { arrayOf } from 'normalizr' 

export function getUsers(data) { 
    return { 
    type: 'GET_USERS', 
    payload: data, 
    meta: { 
     schema : arrayOf(usersSchema) 
    } 
    } 
} 

이 스키마를 통해 변환하는 첫 시도였다. 당신이 arrayOf을 사용할 때와 같은 방식으로 schema.Array를 호출 할 수있는 것처럼 보이지 않으므로 배열 호출을 스키마로 옮길 필요가 있다고 생각했습니다.

import { schema } from 'normalizr'; 

const photos = new schema.Entity('photos') 
const phones = new schema.Entity('phones') 
const user = new schema.Entity('user', { 
    photos: [photos], 
    phones: [phones] 
}) 

const users= new schema.Array('users', user) 

export { users } 

액션은 동일하지만 arrayOf에서 스키마 래핑을 제거했습니다. 모든 사용자 데이터가 정상화되지 않고 결과로 덤프되고 있습니다. 데이터는 사용자 객체 목록이며 각 객체에는 normalizr이 가져와야하는 id가 포함되어 있습니다. 나는 정상적인 사람에게 그것이 내가 생각하는 대상의 배열임을 확인하는 방법을 알아 내려고 애 쓰고있다.

답변

2

schema.Array 키 문자열 이름 (docs)을 허용하지 않습니다. 첫 번째 인수는 스키마 정의 여야합니다. 당신은 단지 하나의 개체 유형의 배열을위한 속기를 사용할 수,

const users = new schema.Array(user) 

을 또는 :

const users = [ user ]; 
+0

흠을 그래서 그 대신

const users= new schema.Array('users', user) 

의 당신은 사용해야합니다. 'index.js : 179 Uncaught Error : Normalize가 스키마를위한 객체를 받아들입니다 .'라고 뱉어 버렸습니다. 긴 형식의 새로운 스키마 .Array (공급자)를 받아 들였지만. 그러나 모든 사용자 객체는 여전히 결과 배열로 덤핑되고 엔티티는 비어 있습니다. 사진과 전화를 제거하여 코드를 단순화하는 데 지쳤습니다. 어쩌면 내가 워드 프로세서에서 더 많은 정보를 찾을거야. – DigitalDisaster

+0

글쎄, 그냥 redux-normalizr이 버전 3과 호환되지 않는 것처럼 보일지 모른다. 스키마가있는 내 감속기에서 'normalize'를 사용할 때 문제가 없다. 미들웨어를 없애야하는 것이 유감이지만 normalizr v3를 사용하게되어 기쁩니다! 고맙습니다! – DigitalDisaster

관련 문제