Skip to content

Commit

Permalink
Move beaker length validation to isValidValue for QSM, see #216
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisklus committed Feb 3, 2020
1 parent 0660402 commit 393c50b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 7 additions & 2 deletions js/common/EFACQueryParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ define( require => {
type: 'array',
defaultValue: defaultElements,
elementSchema: { type: 'string' },
isValidValue: values => _.difference( values, defaultElements ).length === 0 &&
values.length <= EFACConstants.MAX_NUMBER_OF_INTRO_ELEMENTS,
isValidValue: values => {
const beakers = _.filter( values, value => value === EFACConstants.WATER_KEY || value === EFACConstants.OLIVE_OIL_KEY );

return _.difference( values, defaultElements ).length === 0 &&
values.length <= EFACConstants.MAX_NUMBER_OF_INTRO_ELEMENTS &&
beakers.length <= EFACConstants.MAX_NUMBER_OF_INTRO_BEAKERS;
},
public: true
}

Expand Down
8 changes: 1 addition & 7 deletions js/intro/EFACIntroScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ define( require => {
};

const blocksToCreate = [];
let beakersToCreate = [];
const beakersToCreate = [];

// map query parameter string to element type and split by blocks vs beakers
EFACQueryParameters.elements.forEach( elementKey => {
Expand All @@ -61,12 +61,6 @@ define( require => {
}
} );

if( beakersToCreate.length > EFACConstants.MAX_NUMBER_OF_INTRO_BEAKERS ) {
assert && assert( false, `Only ${EFACConstants.MAX_NUMBER_OF_INTRO_BEAKERS} beakers may be added, but \
${beakersToCreate.length} were provided: ${beakersToCreate}` );
beakersToCreate = beakersToCreate.slice( 0, EFACConstants.MAX_NUMBER_OF_INTRO_BEAKERS );
}

super(
() => new EFACIntroModel(
blocksToCreate,
Expand Down

0 comments on commit 393c50b

Please sign in to comment.