datajs (Part 6)

Part 6

datajs is a new cross-browser JavaScript library that enables data-centric web applications by leveraging modern protocols such as JSON and OData and HTML5-enabled browser features.

Under the covers datajs.js is simply a wrapper for the following javaScript files:

  • utils.js
  • xml.js
  • deferred.js
  • odata-utils.js
  • odata-net.js
  • odata-handler.js
  • odata-gml.js
  • odata-xml.js
  • odata-atom.js
  • odata-metadata.js
  • odata-json-light.js
  • odata-json.js
  • odata-batch.js
  • odata.js
  • store-dom.js
  • store-indexeddb.js
  • store-memory.js
  • store.js
  • cache-source.js
  • cache.js

Each of the files provides functions to work with odata calls in your application.

Additional Reading

OData Code Snippets

WinJS Part(5)

Part 5

The Windows Library for JavaScript provides a set of new controls designed for Windows Store apps using JavaScript, such as the WinJS.UI.DatePicker, WinJS.UI.FlipView, WinjS.UI.ListView, and WinJS.UI.Rating controls. It also includes two style sheets (one with a dark color scheme and one with a light) that give your app the look and feel of Windows 8.

The WinJs.UI has the following controls available.

  • AppBar
  • DatePicker
  • FlipView
  • Flyout
  • ListView
  • HtmlControl
  • Menu
  • PageControl
  • Rating
  • SemanticZoom
  • SettingsFlyout
  • TimePicker
  • ToggleSwitch
  • Tooltip
  • ViewBox

The one problem that I have with the WinJS library is that it only works with Windows 8 Windows store applications.

The WinJS namespace provides special Windows Library for JavaScript functionality, including Promise and xhr.

The challenge with WinJS is that many of the features only work on Windows 8 applications.

Additional Reading

Asynchronis Pattern (Part 4)

Part 4

The Event-based Asynchronous Pattern makes available the advantages of multithreaded applications while hiding many of the complex issues inherent in multithreaded design.

Using a class that supports this pattern can allow you to:

  • Perform time-consuming tasks, such as downloads and database operations, “in the background,” without interrupting your application.
  • Execute multiple operations simultaneously, receiving notifications when each completes.
  • Wait for resources to become available without stopping (“hanging”) your application.
  • Communicate with pending asynchronous operations using the familiar events-and-delegates model. For more information on using event handlers and delegates, see Events and Delegates.

By using the Asynch pattern in the LightSwitch HTML client the developer can build responsive user interfaces that are capable of doing a lot of work. Typically we use a BackgroundWorker component when building simple multi-threaded applications but as we start to build more complex solutions we will want to build a set of methods, generally analogous to the ones working on the current thread, to handle the computing. The biggest challenge that I have found in doing this kind of work is the lack of ability to update across threads. With some ingenuity you can overcome this nicely. LightSwitch HTML client solves many of those issues for you as it generates the application.

In the HTML client, we chose to expose promise objects to represent asynchronous work. Promise objects provide the most flexible set of options when working in an asynchronous environment and make it easier to structure code in its logical order of execution.

There are a number of promise object implementations available. We chose to utilize the WinJS implementation of promise objects as it was one of the more complete offerings and provided technical alignment with the Windows 8 development experience.

Additional Reading

Event-based Asynchronous Pattern Overview on MSDN
Using Promise objects with LightSwitch

The User Interface (Part 3)

Part 3

The Microsoft LightSwitch team chose to change the paradigm associated with the user interface of the HTML client.

SDI (Single Document Interface) instead of MDI (Multiple Document Interface) aligns with the ‘Responsive Design’ philosophy of starting with the mobile application and adding functionality for larger view ports. The SDI interface also provides a task oriented UI that works well with phones and tablets.

One of the things that was most difficult for me was to overcome my focus on packing as much on a screen as functionally possible. I focused on minimizing the number of clicks and screens/pages/forms that a user was required to interact with. On a mobile phone or table I really needed to change this philosophy and focus every touch on accomplishing something of significance.

The LightSwitch team also focused on screen reuse, tabbed documents and functional interaction to create the compelling user interface of the HTML client.

Navigation boundaries is another new, at least to me, concept that presents some interesting opportunities and challenges. The Save boundary, the Nested boundary and the None boundary have been defined to provide interaction context within the LightSwitch application.

Navigation Boundaries

Each time a user moves between tabs in a screen, shows a dialog or shows another screen, a navigation boundary is crossed. There are three boundary options that may be applied at a navigation boundary that affect both the navigation to the target and the return from the target to the source.

The Save boundary option is only applicable when showing another screen:

Before navigating to the target, if there are changes in the data workspace the user is prompted to save or discard these changes.
While showing the target, the shell exposes “Save” and “Discard” buttons.
Before returning from the target, if there are changes in the data workspace the user is prompted to save or discard these changes.

The Nested boundary option is applicable when showing a dialog or another screen:

Before navigating to the target, a new nested change set is started on the data workspace.
While showing the target, the shell exposes “OK” and “Cancel” buttons.
Before returning from the target, if there were changes made the user is prompted to keep or cancel these changes.

The None boundary option is applicable for all navigation scenarios (and is the only option available when moving between tabs in a screen):

Before navigating to the target, no specific behavior occurs.
If the target is another screen tab, the shell exposes the previously visible buttons.
If the target is a dialog or another screen, the shell exposes a “Back” button.
Before returning from the target, no specific behavior occurs.

Additional Reading

Responsive Web Design with Ethan Marcotte

The LightSwitch Software Stack (Part 2)

Part 2

In this installment of the series we will be looking at the software stack of LightSwitch HTML Client.
LightSwitch Software Stack

The LightSwitch HTML Client architecture is built on the MVVM (Model View ViewModel) pattern which is an adaptation of the MVC (Model View Controller) pattern. These patterns provide for much better separation of concerns and more maintainable code.

The Stack Components

  • Base. This layer provides functionality used by all the other layers. It mostly builds on and uses the fundamental concepts taken from the WinJS library, such as namespaces, classes, events and promise objects.
  • Model. This layer implements loading, parsing and processing of the LightSwitch application model. The model is converted from its original LSML form into a standard JSON representation for quick and easy consumption at application startup.
  • Shared. This layer implements the concept of a business object, which, represents a base for both entities (data) and screens (view models).
  • Data. This layer implements the LightSwitch data concepts, including entities, data services and data workspaces. It depends on the datajs library for underlying communication with the LightSwitch OData service.
  • View Model. This layer implements the LightSwitch view model concepts, including screens and content items. It also implements the view model for the shell, which includes application-wide commands and the LightSwitch navigation model.
  • View. This layer implements the LightSwitch view concepts, including controls, layout primitives and the visualization of the shell. It depends on the jQuery and jQuery Mobile libraries for DOM manipulation and other browser communication.

The layering of the LightSwitch HTML client architecture provides a solid foundation for enterprise applications that are highly maintainable and scalable. I will be reviewing each of the library components individually in subsequent installments of this series.

LightSwitch HTML Client (Part 1)

Part 1

The new path forward?

I have been surveying the landscape recently trying to decide where to spend my professional development time for the next 12 to 18 months. I have shied way from LightSwitch in the past because it was based on Silverlight and XAML and I didn’t think that either of those technologies were worth any investment of my time. Recently I have been encouraged to take another look at LightSwitch in the HTML client version. I have decided to pursue this since it fits directly inline with my desire to master the HTML5 stack.

The following series of articles will chronicle my learning and evaluation experience.

The Overview

LightSwitch HTML Client is a HTML5 and JavaScript based application development “framework” environment for building touch based applications. Using a responsive design philosophy you can develop applications starting with the handheld device and increasing functionality based on the client environment. Using Visual Studio you can point and click your way to a functional application within minutes. I personally have done it in as little as 30 minutes.
LightSwitch Architecture

As you can see from the above graphic the application developer has a variety of options at their finger tips with the promise of new levels of productivity. Substantially gone are the days of spending hours and hours on plumbing code.

I am excited to embark on this journey and hope that you enjoy coming along with me.

Additional Reading

LightSwitch HTML Client Architectural Overview

HTML5 “Stack”

Lately I have been doing a lot of work with what I am calling the HTML5 Stack.  This stack consists of HTML5, CSS3, JavaScript, jQuery and jQueryUI.

I am very impressed with the breadth of capabilities that the stack delivers to the application developer.  From the much improved semantic correctness of HTML5 to the wonderful new additions to css in CSS3, I have been really enjoying the new play ground.

As simple example…

One of the issues a developer faces is when to put up a message and when to take it down.  This seems like a trivial issue but the orchestration makes it sometimes quite complex.  Say we have an error message that we want to place on the web page but the when and how to dispose of that message can get quite messy.

The other day I focused on the issue for a project and found that with a couple of little lines of code the problem just goes away.

The Page

<meta charset="utf-8" />
<link href="css/ui-lightness/jquery-ui-1.10.1.custom.css" rel="stylesheet" /> 	
<link href="css/myCss.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.10.1.custom.js"></script>

<input id="errorMessage" type="text" value="Yo John" /><a id="lnkClose" onclick="closeErrorMessage()" href="#">x</a>
<input id="showHide" onclick="showErrorMessage('Yo man this is cool', 5000, true)" type="button" value="Show" />


$(function () {

// Show an error message for 5 seconds (1 second = 1000 milliseconds)
showErrorMessage = function (message, duration, IsSticky) {
   if(!IsSticky) {
   else {

closeErrorMessage = function () {

In this example you can now display an error message with a timeout value (1000 = 1 second) or sticky so that the user has to dispose of the error on a case by case basis.

Historically this would have been a task of determining when the event should be shown, when it should be removed, what each of the initiating events would be and on and on. Now it is just show the error set the timeout and move on with the rest of the interaction.

I have decided to spend the next 12 to 18 months really mastering this “stack”. I would be pleased if you would join me on this adventure.