- Lightweight client-side model with rich event features such as propagation, and cascading.
- Unified subscription for both view and model
- Subscription can be registered declaratively, programmatically, or mixed.
- Reusable, functional, asynchronous event handler implemented by workflow and activity.
- Bundled with lots of reusable, composable workflow types, activities, and subscriptions
You can download Harmony from here. Harmony comes with two version, harmony.core.js (13KB) and harmony.js (20KB) which includes 10 plugins. The file size is after minified and gzipped.
- jQuery 1.5+
- jQuery BBQ (optional, required by bookmarkable plugins)
- jsRender (optional, required by jsRender template adapter)
- handlebars.js (optional, required by handlebars.js template adapter)
- matrix.js (optional, required by external template plugins)
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> <script src="http://raw.github.com/fredyang/harmony/master/ref/jquery.ba-bbq.min.js"></script> <script src="http://raw.github.com/fredyang/harmony/master/ref/jsrender.js"></script> <script src="http://raw.github.com/fredyang/harmony/master/ref/matrix.min.js"></script> <script src="http://raw.github.com/fredyang/harmony/master/download/harmony.js"></script>
Is Harmony a MVC framework?
No. Firstly, it does not use controller, secondly, it is not framework, but a library. You can call it Model-View-Subscription library.
MVC pattern works very well at server side. But client-side has some differences from server side, such as:
|Server side||Client side|
|Style||Predetermined machine to machine request/response||Not so predictable user/machine interaction|
|State||Stateless, state is created and destroyed for every request/response session||Stateful, state accumulates for every user interaction,and accumulates with time.|
|Event||No event||Events drive the application.|
|Controller||simple and well-controlled||complicated and hard to control|
Because of the differences, Harmony use publisher-subscriber pattern. In this pattern, views and models take control of themselves by subscriptions. Below are the rules the library follows.
- Views and models are all objects.
- Objects control themselves.
- No object control any other object.
- An object can trigger events of himself.
- An object cannot trigger events of others.
- Objects can subscribe events and react.
- Objects do not act without subscription.
When designing client application, we normally think like, "When this happens, I want to change this like this", such as "When view change, I want to change the model like this", or "When model change, I want to change view like this", or "Let's create a two-way binding between this view and this model, so that they can be synchronized".
Harmony use a different mindset, "When this happens, I want to change myself like this, other people will take care of themselves".
Can I use controller?
Yes, as long as it controls well. For whatever reason, such as performance, directly manipulating others is still required in some cases, you as a developer control what needs to be done.
Can I use with Harmony other MVC frameworks/libraries?
Yes. In Harmony, objects without subscriptions will do nothing, objects with subscriptions will only change themselves not others, so they are very harmless. Harmony is just a library about subscriptions, and it plays well with others.
The core of Harmony is based on the following modules.
- Unified Subscription
Is the view module missing from the list? Yes, but it is deliberate. Most of the view features are taken care by jQuery, Harmony just add a couple of methods to jQuery object. In the following, I will give a overview on how each modules works. For details of each API, please refer to documentation.