DCL

An elegant OOP with mixins + AOP for JavaScript.

dcl6 is coming

New version of dcl is coming: dcl6. This is an experimental version written from the ground up specifically to take advantage of new ES6 language features: new class keyword, new super mechanism. The implementation uses symbols to keep innards truly private.

The principal coding has been finished several months ago, and the new library was under extensive real-world testing. Missing features: debug module is unfinished, and the documentation is in early stages. So right now it is only for brave developers, who feel comfortable reading tests and the code to understand the changed API, and who are not afraid to encounter possible bugs.

Logically, it is based on dcl 2.x branch and supports all advanced ES5 features as well. Of course, it supports chaining and AOP advices we all come to love. It even provides the same set of advices, mixins, and utilities. As before, it has no external dependencies, and minimal in size.

Using dcl with ES6

dcl can be used with projects based on ES6. Unfortunately some tools had problems with dcl in a certain configuration:

  • For Node-based projects the browser globals distribution (see Installation) cannot be used.
  • Tools like webpack are difficult to configure to bypass certain modules from totally unnecessary compilation step.
    • Babel is used to compile from ES6 to ES5 all modules regardless of the fact that dcl uses strict ES5 subset.
    • Babel has problems with UMD unable to decipher static dependencies from it.

To make dcl more Babel-friendly so it can be easily used in React-based projects, or any projects, where tooling is based on webpack, new distribution was introduced: /es6/.

Starting with version 2.0.3 dcl has a special directory /es6/, which contains processed modules with dependencies done in the ES6 style with import statements. They expose their APIs with export default.

New addition: registry

New utility was added to dcl in 2.0.2: registry.

Registry automatically collects all newly-declared constructors, if they define declaredClass property. Later they can be accessed by names. This feature is useful to decouple a declaration of a constructor from places that use it, and for debugging purposes. It provides a Map-like API, so users can inspect and manipulate the registry.

New major release: 2.0

New major release 2.0 for Node and ES5 browsers builds on 1.x branch, and adds following features:

  • Simplified API.
  • Supports ES5 features: getters, setters, generic property descriptors.
    • Internally all properties are defined using ES5 property descriptor API.
  • Properties can be defined using the classic object notation, and the list of property descriptors.
  • New decorator: dcl.prop().
    • Property descriptors can be specified directly.
    • Getter and setters can be advised as easy as regular methods.
    • Supports “class”-wide defaults for configurable, enumerable, and writable.
  • detectProps mode can detect property descriptors in-line without decorators.
  • Node’s require() import, and AMD are supported out of box.
  • For convenience a version based on browser globals is provided.

1.1.3: micro update

1.1.3 introduces a check against a wrong type of super (e.g., making a super call for numeric property), adds new CI targets, and fixes a version for bower.

This is a minor release, which can be safely skipped by most users.

1.1.2: technical release

1.1.2 is an intermediate technical release. While the interface and the functionality were not affected, internals were refactored, and updated to improve their readability and maintainability.

This update can be safely skipped by most users, yet I advise to test it against your codebase, because it will serve as a foundation for the upcoming major version.

Micro update: 1.1.1

New release of dcl (1.1.1) includes two minor bug fixes:

  • Bugfix: a stray comma in a test file, which acted up in legacy browsers.
  • Bugfix: dcl.mix() was called directly in the base modules preventing it from being monkey-patched.

Most users can safely skip this update, unless they are directly affected by the monkey-patch bug.

1.1: legacy

This is a major update, which includes support for legacy browsers (IE < 9). It doesn’t affect existing users, because it doesn’t change the API or its semantics, but provides an option for legacy applications. It is considered “major” because it changes some internal plumbing.

legacy.js documentation contains all necessary background information for the change, and recommendations on how to use it in real projects.

1.0.4: added to Bower

This is a technical release, which doesn’t change the functionality in any way. You can safely skip it.

The version bump was required in order to add dcl to bower — a generic, unopinionated solution to the problem of front-end package management. If you use Bower to manage your project dependencies, you can install dcl like this:

1
bower install dcl

Update: 1.0.3

New update was pushed out. Changes:

  • Bugfix: in some cases when using a native constructor created without dcl it was not called when creating an object. This bug is fixed and relevant tests were added.
  • All tests are consolidated using heya-unit. No more manual tests.
  • Added an automated testing in PhantomJS environment.
  • Increased test coverage.

This update is about maintenance. It doesn’t introduce new features. Given that the fixed bug is quite exotic, this update can be skipped unless your code contains a mix of dcl and non-dcl bases and mixins in the same constructor functions.