Fork me on GitHub

brook

a JavaScript framework for large scale development

Sample Code

you can write the application using MVC design pattern easily,
like this:
Namespace("sample.widget")
.use("brook *")
.use("brook.model *")
.use("brook.util *")
.define(function(ns){
  var observeEvent = function(element, eventName, promise) {
    element.addEventListener(eventName, function(event) {
      promise.run(event)
    }, false );
  };

  //define view method
  var updateView = function(element) {
    return ns.promise(function(next, value) {
      element.innerHTML += value + "<br>";
      next();
    });
  };
  
  //define model
  var model = ns.createModel();
  model.addMethod("update", ns.promise(function(next, value) {
    //update model
    //for example, connectToSomeDataBase();
    //then, Model to View
    next("Hello World!");
  }));

  ns.provide({
    registerElement: function(button, element) {
      // handle user action and notify to the model
      // View to Model
      observeEvent(button, "click", model.notify("update"));

      //observing model update
      ns.from(model.method("update")).bind(updateView(element)).subscribe();
    }
  });
});

//entry point
Namespace.use("sample.widget").apply(function(ns) {
  ns.sample.widget.registerElement(
    document.getElementById("sampleButton"),
    document.getElementById("output")
  );
});
sample code output here

Document

document

Authors

Daichi Hiroki (hirokidaichi@gmail.com)
Kato Kazuyoshi (kato.kazuyoshi@gmail.com)

Contact

hirokidaichi (hirokidaichi@gmail.com)

Dependencies

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/hirokidaichi/brook