Vitruvio
Is a framework which extends JavaScript capabilities in order to allow developing OOP applications over an structural well designed architecture by defining: namespaces, classes, interfaces, enumerators, inheritance, exceptions and other resources. Altogether with the solid class system proposed, it offers:
- An extensible Exception hierarchy
- Event management system
- Genericity checkouts over objects.
- JXON and XML parser.
- JSONP, AJAX and WebSocket client implementations
- Basic DOM utility classes (Browser only).
- A dynamic and extensible resources loader system highly compatible over web browsers and node js which allows customizations.
- Cryptography encoder/decoder (UTF8, Base64).
Environments and browser support
Vitruvio runs server side on Node.JS and client side suports the following browsers on desktop and mobile devices:
Google Chrome
Microsoft Edge
Mozilla Firefox
Opera
Safari
Internet Explorer ver. 5+
How to use
Step 1, get it down!
Over NodeJS it can be easyly downloaded and installed with:
npm install vitruvio --save
or can be downloaded via Right click/Save as: latest realeased
Step 2, include it in your code!
Vitruvio exports the System namespace which is the main namespace of the framework and contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions. For this reason is highly recommended to name it on source code as System.
On NodeJS using require:
var System = ;
On html pages:
<...><...>
Step 3, get System's globals
var using = Systemusing; // Resources solver function // Main functions and resourcesvar Namespace = ;var Class = ;var Interface = ;var Enum = ;...
Step 4, lets define some classes!
// on file src/com/example/Animal.js // on file src/com/example/Dog.js // on file src/main.js // Load and get the Dog class reference asynchronously;
Once a class has been loaded, you can get its reference:
var MyClass = ;
Is and As operators
One of the most advanced capabilities of Vitruvio framework is the ability to cast objects to a specific type and to check instances out by its type.
Is operator example: Pure JavaScript:
try ... catche ifetype == "Error" // Do something // or ife instanceof Error // Do something
Vitruvio schema:
try // Some code which throws an error. throw "My Custom message"; catche // The is operator in most cases will do the same as the instanceof JavaScript operator. ife // Do something else ife // Base System.Exception class // Do something else // Third party and basic JavaScript errors // Do something
As operator: Pure JavaScript:
...
Vitruvio schema:
// on file src/com/example/ifaces/Runnable.js // on file src/com/example/tasks/DownloadTask.js // on main.js filevar Runnable = ;var DownloadTask = ; var task = ; var runnable = task; // the casted runnable instance will only contain the run method.