Skip to content

Commit

Permalink
optimized call # to Hoek Reach
Browse files Browse the repository at this point in the history
  • Loading branch information
Lam Chan committed Feb 18, 2017
1 parent 5e8105b commit 0638128
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,9 @@ internals.object = function (schema, options) {
Object.keys(schemaDescription.children).forEach((childKey) => {

const childSchema = schemaDescription.children[childKey];
const childIsOptional = Hoek.reach(childSchema, 'flags.presence') === 'optional';
const childIsForbidden = Hoek.reach(childSchema, 'flags.presence') === 'forbidden';
const flagsPresence = Hoek.reach(childSchema, 'flags.presence');
const childIsOptional = flagsPresence === 'optional';
const childIsForbidden = flagsPresence === 'forbidden';
const shouldStrip = Hoek.reach(childSchema, 'flags.strip');

if (shouldStrip || childIsForbidden || (childIsOptional && !(Hoek.reach(options, 'config.includeOptional')))) {
Expand Down
5 changes: 3 additions & 2 deletions lib/joiGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ const generate = function (schemaInput, options) {

childrenKeys.forEach((childKey) => {

const childIsOptional = Hoek.reach(schemaDescription.children[childKey], 'flags.presence') === 'optional';
const childIsForbidden = Hoek.reach(schemaDescription.children[childKey], 'flags.presence') === 'forbidden';
const flagsPresence = Hoek.reach(schemaDescription.children[childKey], 'flags.presence');
const childIsOptional = flagsPresence === 'optional';
const childIsForbidden = flagsPresence === 'forbidden';

if (childIsForbidden || (childIsOptional && !(Hoek.reach(config, 'includeOptional')))) {
return;
Expand Down

0 comments on commit 0638128

Please sign in to comment.