The MVC folder structure of our validation app extends the structure
of the minimal app by adding a lib
folder containing the
generic code libraries browserShims.js
,
errorTypes.js
and util.js
. Thus, we get the
following folder structure:
publicLibrary css main.css normalize.min.css lib browserShims.js errorTypes.js util.js src c m v index.html
We discuss the contents of the added files in the following sub-sections.
We add three library files to the lib
folder:
browserShims.js
contains a definition of the
string trim function for older browsers that don't support this
function (which was only added to JavaScript in ES5, defined in
2009). More browser shims for other recently defined functions,
such as querySelector
and classList
,
could also be added to browserShims.js
.
util.js
contains the definitions of a few
utility functions such as isNonEmptyString(x)
for
testing if x
is a non-empty string.
errorTypes.js
defines classes for error (or exception) types
corresponding to the basic types of property constraints discussed above:
StringLengthConstraintViolation, MandatoryValueConstraintViolation, RangeConstraintViolation,
IntervalConstraintViolation, PatternConstraintViolation, UniquenessConstraintViolation. In
addition, a class NoConstraintViolation is defined for
being able to return a validation result object in the case of no constraint
violation.
The start page index.html
takes care of
loading CSS page styling files with the help of the following two
link
elements:
<link rel="stylesheet" href="css/normalize.min.css"> <link rel="stylesheet" href="css/main.css">
Then it loads the following JavaScript files:
browserShims.js
and util.js
from
the lib
folder, discussed in Section 4.1,
errorTypes.js
from the lib
folder,
defining exception classes.
initialize.js
from the src/c
folder, defining the app's MVC namespaces, as discussed in Chapter 3
Book.js
from the src/m
folder, a
model class file that provides data management and other functions
discussed in Section 5.