geraintluff/tv4 — pull request #18 by oravecz (2013-04-11 20:49:00+00:00)
Title: Multithreaded Support

Refactored the code to allow a single instance of tv4 to be used in a multithreaded environment. This is desirable because many use cases of tv4 are in a server environment where supporting schemas should only be loaded once. Once configured like this, tv4 can be called multiple times to validate many data objects.

The major change from an API standpoint comes in the form of the return type from a call to:
var result = tv4.validate(data, schema);

Result will contain the following properties:
{Boolean} valid - true if the data object validates against the schema
{Array} missing - an array of schema urls that could not be loaded. An
empty array if all schema files were discovered.
{Array} errors - an array of ValidationError objects. Validation currently
aborts after the first detection of an error, so only the first error will be
included. I used an array because I hope the library will validate the
entire data object at some point.

Removed the global objects (error, missing) and created a clone of the schemas array in order to support a single instance of tv4 being run in a multi-threaded environment. Updated the tests to conform with a new return result.