JSU: JavaScript Utilities

Introduction

Building on composable, testable components is key to developing quality software efficiently. Unfortunately, the Web programming environment presents a number of challenges that must be overcome:

To address these challenges, we employ a number of conventions and libraries. The crank-js package provides tooling and build rules, and this package provides libraries.

Packaging

Modules are defined using a subset of node.js (“common JS”) conventions:

Modules can thereby avoid the use of globals for importing of exporting, and source files can be scanned for dependencies.

Testing: crank-js

Each module can be accompanied with a *_q.js file that performs automated tests. These tests will be run with Node.js.

When using the JavaScript in a web page, we bundle a module along with all of its dependencies and a simple package loader into a single script. This can then be embedded in, or loaded by, a web page.

CSS Management: view.js

The View module allows DOM element styles and behavior to be constructed modularly. Instead of being split between CSS and JavaScript files, a single module can contain:

With the implementation in one module, packaging conventions allow bundling and dependency scanning to be automated.

Programmers deal only with the JavaScript namespace and can stop dealing with CSS's global namespace and the potential for conflicts that it presents.

CSS properties can be grouped into subclasses of View, and inheritance can be used to construct sub-classes. This avoids the repetition common in CSS files.

Although CSS properties are described in JavaScript, the View module constructs CSS classes and style sheet rules dynamically so that elements can be constructed efficiently.

Other Libraries

anim.js simplifies animations.

class.js simplifies building classes and subclasses in JavaScript.

psarray.js implements an array-like persistent data structure.

observable.js implements observable objects, which propagate mutable state.

oweb.js implements observables that propagate state changes from a web server.

spiltter.js is a UI control for dividing the content area amongst two child elements.