New and Modern Tricks Modules, Namespacing “Separation of Concerns” Model, View, Controller (MVC): Request Routing (Controller) Object Relational Mapping (Model) Templating (Views) Binary, UTF-8, JSON, Callbacks Concise and Elegant
Why JS on the Server Code re-use, sure.. Real strength: Heaps of stuff already written and tested: Parsers, Crypto, ORM, Testing, etc. (I’ve even seen a Linux Emulator) Expressive and Powerful: Callbacks/handlers, Query Iteration, flexible inheritance, extendibility (override built-in methods) Poor dates, formatting, etc. But easily fixed.
The Framework Event Binding Bind to the “ready” event to attach controller code / route handlers Routes: Sinatra-style; named parameters Modules: load modules similar to common-JS Templating: compile your data in the route handler and then use template module to render your view Data Models: create your models, validation, methods and relationships Clean separation of code, helpful, intuitive interface
ActiveRecord Models are defined inside app/models Ported from Aptana’sActiveJS
Model Validation and Relationships hasOne, hasMany, belongsTo validatesPresenceOf, validatesUniquenessOf, validatesLengthOf, etc Custom Validation functions and getter Methods
Weaknesses and Future Development Needs better testing library (qunit) Debugging could be easier SQLite Adapter almost Working on adapters for other Server JS platforms (Apache + v8, Rhino on JVM) Good abstraction layers makes it not too closely coupled to current platform
Wrapping Up What can be learned from Do It Yourself Not Re-inventing the Wheel Re-using other open-source code Github: http://github.com/sstur/aspjs