Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 14x 14x 14x 14x 7x 14x 14x 14x 49x 49x | // @flow
import forEach from 'lodash/forEach';
import {createField} from './utils';
import NullField from './nullField';
import {types} from './types';
import type {Field} from './types';
export default class ObjectField implements Field {
schema: any;
rootSchema: any;
key: string;
isEntity: boolean;
constructor({rootSchema, schema, key, isEntity}: {rootSchema: any, schema: any, key: string, isEntity?: ?boolean}) {
this.key = key;
this.rootSchema = rootSchema;
this.schema = schema;
this.isEntity = isEntity || false;
}
getKey() {
return this.key;
}
exists() {
return true;
}
getType() {
return types.OBJECT;
}
getChild(fieldName: string) {
if (!this.schema.items || !this.schema.items[fieldName]) {
return new NullField({key: fieldName});
}
const field = createField(fieldName, this.rootSchema, this.schema.items[fieldName]);
return field;
}
forEach(visitor: Function) {
Iif (!this.schema ||
!this.schema.items
) {
return;
}
forEach(this.schema.items, (item, key) => {
const field = createField(key, this.rootSchema, this.schema.items[key]);
visitor(field);
});
}
}
|