0
ネストされたスキーマで定義された一意のエンティティキーのリストを取得し、&は、私はシンプルなスキーマのために必要なものを行う関数を書かれている:私はnormalizrスキーマで定義されたすべてのキーのリストを取得しようとしている
export const collectAttributes = target => {
const schemaKeys = []
if (target.hasOwnProperty('_key')) {
schemaKeys.push(target._key)
}
const definitions = Object.keys(target).filter(key => key[0] !== '_')
definitions.forEach(key => {
collectAttributes(target[key]).forEach(attribute => schemaKeys.push(attribute))
})
return schemaKeys
}
このテストケースで示されているようしかし、これは、Maximum call stack size exceeded
エラーでネストされたスキーマの定義に失敗します。
describe('collectAttributes',() => {
it('should collect all unique collections defined on a recursive schema',() => {
const nodeSchema = new schema.Entity('nodes', {})
const nodeListSchema = new schema.Array(nodeSchema)
nodeSchema.define({ children: nodeListSchema })
expect(collectAttributes(nodeSchema)).toEqual(['nodes'])
})
})
誰もが再帰関数が停止するような、既に訪問したスキーマを収集する方法についてのアイデアを持っている場合は、彼らはとても有難い。