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.
Posts in the ‘JavaScript’ Category
Learning Dojo
Friday, March 5th, 2010Pintura JSGI Modules
Thursday, March 4th, 2010Pintura 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:
function(request){
… my JSGI application …
});
CommonJS Utilities
Tuesday, March 2nd, 2010CommonJS 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
}
};
Getting Started With Pintura
Monday, January 25th, 2010Pintura 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.
Introducing Pintura
Friday, January 22nd, 2010Pintura is a CommonJS/JSGI-compliant, server-side JavaScript-based framework for building rich Internet application with the REST architectural style, thin storage-oriented server design, and the consistency of end-to-end JavaScript. The Pintura framework forms the core of Persevere 2.0, and is the first framework built to run on multiple CommonJS platforms like node.js, Narwhal/Jack, and Flusspferd/Zest. It utilizes a layered approach to application development that facilitates straightforward, modular web applications.
Pintura is not a traditional MVC web server framework, which often conflate presentation and interaction concerns across the client and server, but rather follows the REST prescription of maintaining simple storage and serialization oriented server also known as thin server architecture or SOFEA. Pintura is designed to cleanly separate the concerns of presentation and interaction on the client, and storage and model logic concerns on the server. This design fits perfectly with comprehensive JavaScript frameworks like Dojo, General Interface, Cappuccino, YUI, and ExtJS that provide client-side MVC. In particular, Dojo has excellent support for standards-based JSON REST interaction that matches perfectly with this server-side framework.
Managing Widget Templates in Dojo 1.4
Wednesday, January 20th, 2010This article introduces dojo.cache and presents a technique for externalizing your widget templates in swappable configuration files, where they can be referenced by a custom templateKey widget property.
Introducing dojo.cache
Dojo 1.4 adds a new core utility called dojo.cache. To appreciate it we first have to review how Dijit’s templatePath works. When you define a _Templated widget with a templatePath property, the content from that URL is fetched the first time you instantiate the widget, and made available as a string. All subsequent instances get the cached string. Furthermore, when you run a build, your templatePaths get replaced with templateStrings and their content is inlined into the output from the build. This improves performance considerably by removing those synchronous XHR requests, while remaining transparent to the developer.
dojo.cache generalizes this pattern, making the same functionality available from Dojo Core—synchronous, cached content retrieval that gets inlined during the build. dojo.cache usage is much like dojo.moduleUrl:
my.stringResource = dojo.cache("module.path", "relative.path.html" );
CommonJS/JSGI: The Emerging JavaScript Application Server Platform
Tuesday, January 19th, 2010CommonJS (formerly known as ServerJS) has become the essential hub around the development of server side JavaScript (SSJS). SSJS for years has suffered from fragmentation, but the CommonJS project has provided the momentum to bring different frameworks together and start building interoperable modules. SSJS is ripe with potential; JavaScript has been soaring in popularity and the ECMAScript 5 specification was recently accepted. JavaScript has proven itself as the language of the web’s client-side (even ActionScript is a derivative of JavaScript). The opportunity to use the same language on both client and server is certainly most realistic and viable with JavaScript as it avoids the need for translation.
CommonJS
CommonJS has focused on developing critical APIs for building reusable modules, particularly for server-side JavaScript environment. The server-side is generally based around database interaction, file I/O, HTTP serving, and the generation of data formats and HTML, whereas the client-side is based around DOM manipulation and the browser object model. There are certainly APIs that can be used on both sides, and JavaScript on the client and server invites the reuse of APIs where possible. The WebWorker, Indexed Database, and XHR APIs are promising to be enormously beneficial on the server side, and with excellent client server consistency. But still the server side requires special attention, and CommonJS is bringing the needed standards and conventions.
Dojo 1.4 Released!
Thursday, December 10th, 2009Dojo 1.4 is hot off the presses, with more than seven months of significant improvements to performance, stability, and features.
Of particular interest:
- IO Pipeline topics
- dojo.cache
- dojo.contentHandlers
- dojo.hash with native HTML5 onhashchange event support where available
- Traversal and manipulation for NodeLists (the return value for dojo.query)
- dojo.ready (easier to type than dojo.addOnLoad)
- Hundreds of refinements to the Dijit API and collection of Dijits, and a few new widgets in DojoX
- DataChart widget and other improvements to charting
- dojox.drawing lands!
- Editor improvements and new plug-ins in both Dijit and DojoX
- Grid is faster, and the EnhancedGrid lands!
- ForestStoreModel for the TreeGrid
- GFX improvements
- dojox.jq, a very experimental module aimed at trying to match the jQuery API as close as possible, but using Dojo underneath
- Dojo build system optionally supports the Google Closure Tools compiler
- Significant speed improvements, especially in IE
Read the full Dojo 1.4 release notes for more details! And thanks to everyone in the Dojo community that helped make this release great!
JSON Namespacing
Wednesday, September 2nd, 2009(or “Why JSON Hyper Schema means JSON doesn’t need XML’s namespacing colon cancer”)
I recently posted a proposal for an addition to JSON Schema, called JSON Hyper Schema, for defining the properties of a JSON structure that represent links or references within data structures. This is intended to provide the same linking capabilities of JSON Referencing, but in a much more flexible manner such that schemas can be used to describe link information in existing data structures without requiring a fixed convention. I wanted to exposit one of the further benefits of using this type of schema: satisfying the goals of namespacing in JSON.
Narwhal on Persevere
Tuesday, September 1st, 2009Narwhal is an open source toolkit for server-side JavaScript that delivers a growing library of useful modules implementing the CommonJS standard library API. CommonJS is an effort to provide a standard library for server side JavaScript (or JavaScript in any privileged environment) and Narwhal is the most extensive implementation of the library API. Narwhal provides numerous system level functions and IO capabilities with streaming and File interaction.
Persevere is a framework for server-side JavaScript with object persistence and direct mapping to RESTful HTTP interaction. These two projects can complement each other very nicely and since Persevere implements the CommonJS API for module loading, Narwhal’s standard library of modules can now easily be utilized within Persevere.
