Teaching Old JavaScript New Tricks<br />Experiences building a server-side JavaScript framework<br />
Old JavaScript<br />Over 15 years old<br />Implemented everywhere:<br />Browsers, Web Servers, Scripting, Phones<br />Serv...
New and Modern Tricks<br />Modules, Namespacing<br />“Separation of Concerns”<br />Model, View, Controller (MVC):<br />Req...
Microsoft Javascript<br />JScript on IIS (ASP)<br />Not modern or cool, but old, stable and Windows hosting can be found e...
Why JS on the Server<br />Code re-use, sure..<br />Real strength: Heaps of stuff already written and tested:<br />Parsers,...
The Framework<br />Event Binding<br />Bind to the “ready” event to attach controller code / route handlers<br />Routes:<br...
Into the Code<br />Hello World:<br />
Named Parameters<br />Access to URL params<br />Automatic JSON Output<br />
Using Libraries<br />Similar to require() but uses lib()<br />
Application Structure<br />/app<br />/config<br />/controllers<br />/models<br />/system<br />/views<br />/assets<br />Pub...
Now the Cool Stuff<br />ActiveRecord for JavaScript<br />Powerful modeling, no writing SQL<br />HTML Parser, DOM implement...
ActiveRecord<br />Models are defined inside app/models<br />Ported from Aptana’sActiveJS<br />
Model Validation and Relationships<br />hasOne, hasMany, belongsTo<br />validatesPresenceOf, validatesUniquenessOf, valida...
Creating, Updating and Finding<br />See Code<br />
jQuery Server Side DOM<br />See Code<br />
Weaknesses and Future Development<br />Needs better testing library (qunit)<br />Debugging could be easier<br />SQLite Ada...
Wrapping Up<br />What can be learned from Do It Yourself<br />Not Re-inventing the Wheel<br />Re-using other open-source c...
Teaching old java script new tricks
Upcoming SlideShare
Loading in …5
×

Teaching old java script new tricks

750 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
750
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Teaching old java script new tricks

  1. 1. Teaching Old JavaScript New Tricks<br />Experiences building a server-side JavaScript framework<br />
  2. 2. Old JavaScript<br />Over 15 years old<br />Implemented everywhere:<br />Browsers, Web Servers, Scripting, Phones<br />Server Implementations (Old):<br />Netscape, Rhino (JVM), Microsft IIS<br />Old JavaScript feels “old”<br />Namespacing, polluted globals, poor inheritance, not very modular..<br />Those platforms don’t give you much<br />
  3. 3. New and Modern Tricks<br />Modules, Namespacing<br />“Separation of Concerns”<br />Model, View, Controller (MVC):<br />Request Routing (Controller)<br />Object Relational Mapping (Model)<br />Templating (Views)<br />Binary, UTF-8, JSON, Callbacks<br />Concise and Elegant<br />
  4. 4. Microsoft Javascript<br />JScript on IIS (ASP)<br />Not modern or cool, but old, stable and Windows hosting can be found everywhere<br />JScript.dll updated with IE (up to 8) so it’s not ancient<br />Not JScript.NET, not JIT, but quick enough (compared to other interpreters of it’s era)<br />
  5. 5. Why JS on the Server<br />Code re-use, sure..<br />Real strength: Heaps of stuff already written and tested:<br />Parsers, Crypto, ORM, Testing, etc.<br />(I’ve even seen a Linux Emulator)<br />Expressive and Powerful:<br />Callbacks/handlers, Query Iteration, flexible inheritance, extendibility (override built-in methods)<br />Poor dates, formatting, etc. But easily fixed.<br />
  6. 6. The Framework<br />Event Binding<br />Bind to the “ready” event to attach controller code / route handlers<br />Routes:<br />Sinatra-style; named parameters<br />Modules: load modules similar to common-JS<br />Templating: compile your data in the route handler and then use template module to render your view<br />Data Models: create your models, validation, methods and relationships<br />Clean separation of code, helpful, intuitive interface<br />
  7. 7. Into the Code<br />Hello World:<br />
  8. 8. Named Parameters<br />Access to URL params<br />Automatic JSON Output<br />
  9. 9. Using Libraries<br />Similar to require() but uses lib()<br />
  10. 10. Application Structure<br />/app<br />/config<br />/controllers<br />/models<br />/system<br />/views<br />/assets<br />Public files (css, images, etc)<br />
  11. 11. Now the Cool Stuff<br />ActiveRecord for JavaScript<br />Powerful modeling, no writing SQL<br />HTML Parser, DOM implementation and jQuery on the Server<br />Read html files from file system and populate with dynamic content<br />Webpage scraping with ease<br />Node.js based dev-server<br />Uses windows scripting host behind Node to use framework without<br />Schema-less doc-store, Binary, Crypto, Advance language/full-text-search features, Persistent sessions with namespacing, etc.<br />
  12. 12. ActiveRecord<br />Models are defined inside app/models<br />Ported from Aptana’sActiveJS<br />
  13. 13. Model Validation and Relationships<br />hasOne, hasMany, belongsTo<br />validatesPresenceOf, validatesUniquenessOf, validatesLengthOf, etc<br />Custom Validation functions and getter Methods<br />
  14. 14. Creating, Updating and Finding<br />See Code<br />
  15. 15. jQuery Server Side DOM<br />See Code<br />
  16. 16. Weaknesses and Future Development<br />Needs better testing library (qunit)<br />Debugging could be easier<br />SQLite Adapter almost<br />Working on adapters for other Server JS platforms (Apache + v8, Rhino on JVM)<br />Good abstraction layers makes it not too closely coupled to current platform<br />
  17. 17. Wrapping Up<br />What can be learned from Do It Yourself<br />Not Re-inventing the Wheel<br />Re-using other open-source code<br />Github: http://github.com/sstur/aspjs<br />

×