Posts in the ‘JavaScript’ Category

Dojo 1.5: Ready to power your web app

Thursday, July 22nd, 2010

Dojo Toolkit 1.5 is now available for immediate download. Dojo is a JavaScript toolkit that is lean enough for use on a simple blog, yet powerful enough to scale to solve the most advanced web application engineering challenges, allowing you to use just the features and flexibility needed for your application. The 11th major Dojo release, version 1.5 offers many important improvements and enhancements and remains as IP-safe, freely-licensed, and free to use as the first release over five years ago.

(more…)

Real-time Comet Applications on Node with Tunguska

Monday, July 19th, 2010
This entry is part 8 of 8 in the series Server-Side JavaScript, Pintura, and Persevere 2.0

Node is a server-side JavaScript platform that is known for being well suited for Comet-style applications that utilize long-lived connections to allow applications to send messages from the server to the browser asynchronously. In fact, the beginning of the front page of nodejs.org starts out with an example of a web application that delays for a couple seconds before sending a response without any type of blocking; the code is asynchronous and efficient.

However, building a real-life real-time application involves more than just a platform that gives you asynchronous communication, there are a number of other important techniques to understand. We will look at these techniques and introduce project Tunguska that provides some helpful tools to assist in building applications. While a number of Comet projects out there attempt to provide a black box solution to Comet, Tunguska recognizes that most real-time applications involve deep integration into the application and its security, messaging, and data structures. Consequently Tunguska is a set of tools for building real-time applications rather than a closed black box that can’t easily be integrated with. Let’s look at some of these tools.

(more…)

Asynchronous CommonJS Modules for the Browser (and Introducing Transporter)

Friday, July 16th, 2010

Modules are an integral architectural piece of robust application development since they allow individual components to be developed with proper dependency management. Modules can specify dependencies and these can be automatically resolved and loaded to bring various pieces together automatically. In application development this is vastly more scalable and easier than having to track all the different dependencies and manually load modules or insert script tags.

The CommonJS module format is increasingly ubiquitous as the de facto module format for JavaScript. However, if CommonJS modules, by themselves, are directly executed, they require synchronous loading of modules. Synchronous loading is known to be very problematic in the browser since it locks the browser user interface, requires eval-based compilation of scripts which confuses debuggers, and is less efficient than using standard script tags.

(more…)

JSGI vs Connect for Node Middleware

Friday, June 11th, 2010

JSGI (JavaScript gateway interface) is the broadly adopted standard for server-side JavaScript web applications and middleware. JSGI is designed specifically for ease of use in asynchronous, evented environments, and consequently JSGI has been a perfect fit building applications on Node. JSGI-Node has existed for sometime as lightweight JSGI server/adapter for running JSGI-based applications on Node. However, “Connect” was recently released as a new alternate middleware system for Node. This spurred me to make sure JSGI-Node was optimized, and compare the Connect middleware design to JSGI.

(more…)

Resource Oriented Programming

Sunday, May 9th, 2010

The REST architecture has become increasingly recognized for its value in creating scalable, loosely coupled systems. REST is presented as a network interaction architectural style, not a programming methodology. However, the principles of REST can actually be very meaningfully and beneficially applied in the programming realm. We will look at how the resource oriented approach of REST can be applied as principles for programming language usage and design. The motivation for looking at REST should be clear. Little in history has been as ridiculously successful and scalable as the web, and REST is a retrospective look at the principles that were employed in designing the core technologies of the web, particularly HTTP. Applying such proven principles to our application design will certainly be beneficial.

Roy Fielding’s REST architecture is broken down into seven constraints (and the four sub-constraints of the uniform interface). The individual concepts here are certainly not new, but collectively looking at these concepts as resource oriented programming may provide an interesting new perspective. I will also look at how these principles are exemplified in Persevere 2.0 in its object store framework, Perstore, and its web stack Pintura.

(more…)

Understanding dojo.require

Monday, March 29th, 2010

Dojo provides a feature-rich system for including JavaScript modules. Before we begin this journey to explore this concept in depth, you should know that absolutely no knowledge of the Dojo module, packaging, and build system are required to use Dojo.

You can easily get started using Dojo by using a script element referring to a copy of Dojo on the AOL or Google CDNs. If you want to host your own version of Dojo, you can easily download dojo.js, include it in a web page using a script element, and be off and running with Dojo Base.

For those new to Dojo, the following resources give a quick overview of Dojo Base:

In general, dojo.js is a lot like jquery.js or prototype js: you get a competitive set of features founds in most JavaScript libraries that are essential for building great web applications. Those features include:

  • JavaScript Language Helpers
  • Object utilities
  • Array utilities
  • DOM Manipulation
  • A normalized event system
  • Ajax & Cross domain requests
  • JSON utilities
  • Simple effects
  • Browser sniffing

(more…)

Learning Dojo

Friday, March 5th, 2010

There is so much existing information about the Dojo Toolkit that it can be challenging to know where to begin. The following is a Dojo curriculum (I use this term loosely) highlighting community resources and a logical path for self-learning the foundational parts of Dojo.  If you understand the purpose of a variable and function, or you are new to Dojo, then this is for you.

(more…)

Pintura JSGI Modules

Thursday, March 4th, 2010
This entry is part 5 of 8 in the series Server-Side JavaScript, Pintura, and Persevere 2.0

Pintura is a REST-style web framework that provides a comprehensive solution for Ajax-based thin-server applications. However, Pintura has a very modular design, and many of the modules in Pintura are extremely useful as standalone JavaScript/CommonJS components that can be used with Node, Narwhal and other projects. Let’s look at the JSGI middleware modules. JSGI middleware modules are designed to be used in a JSGI HTTP request handling stack, adding functionality to a web application. An example of using a JSGI middleware:

exports.app = MiddleWare( // wrapped my application with middleware
  function(request){
     … my JSGI application …
  });

(more…)

CommonJS Utilities

Tuesday, March 2nd, 2010
This entry is part 4 of 8 in the series Server-Side JavaScript, Pintura, and Persevere 2.0

CommonJS Utils is a collection of general purpose CommonJS-compliant modules. These modules can be used on Narwhal, Node, and other CommonJS platforms. The modules include:

  • json-schema.js – This is a JSON Schema validator module. It can be used to validate data structures using JSON schema definitions. For example:
    var validate = require("json-schema").validate;
    var data = {name: "Test"};
    var schema = {
      properties: {
         name: {type: "string"},
         age: {type: "number"}
      }
    };
    var validation = validate(data, schema);
    validation.valid -> false
    validation.errors -> indicates that age was not provided
    data.age = 30;
    var validation = validate(data, schema);
    validation.valid -> true
     

    This module also supports using standard native constructors as type definitions. The schema above could be written
    more briefly:

    var schema = {
      properties: {
         name: String,
         age: Number
      }
    };
     
  • (more…)

Getting Started With Pintura

Monday, January 25th, 2010
This entry is part 3 of 8 in the series Server-Side JavaScript, Pintura, and Persevere 2.0

Pintura is a REST-style web framework that utilizes a layered approach to application development that facilitates straightforward, well-designed rich internet applications. Pintura forms the core web framework for Persevere 2.0, and consists of a powerful data modeling and persistence framework called Perstore, in combination with a REST-style web framework. You can read more about the goals and principles behind Pintura, but here we will look at how to get started writing applications.

Pintura-based applications normally consist of server-side data models with three layers: data stores, store models, and model facets. On top of this, different representation handlers (for serializing data to different formats) can be defined, but Pintura comes with a good set of these ( including JSON, JavaScript, multipart, and Atom), so usually that is not necessary. This provides a well-structured separation of concerns, distinguishing storage configuration (data stores), core data logic (models), varying capabilities of access to the data (facets), and data serialization (representations). Perhaps the easiest way to understand this approach to take a look at an example application.

(more…)