Group




      h-ubu
 CDI in JavaScript
        Clement Escoffier
How do we do that
    in Java ?
Components
Interfaces
Dependency
 Injection
What do we have
 in JavaScript ?
Module Patterns

      +               -
Fix visibility   A bit complex
                 No interfaces
Module loaders

     +                -
Avoid <script>    Hard-coded
  Transitive     dependencies
   Reuse
MVC / MVVM

    +              -
   Code
                Pushing
organization
               the limits
UI Bindings
Well, so what’s
   h-ubu ?
Service-based
  Injection
 Framework
hub
components
var component = {
    configure : function(hub, conf) { },
    getComponentName : function() { },
    start : function() { },
    stop : function() {}
};



hub
      .registerComponent(component)
      .start()
contracts
var myService= {
    doSomething : function() {}
}
services
services
                      Service
                      Registry
  2 – Lookup,                      1 - Publication
Service Listener     3 - Binding
Substitutability
                   Loose-coupling



   Why services ?
                    Testable
Dynamic
var provider = {
    configure : function(hub, conf) {
        hub.provideService({
            component: this,
            contract: myService
        });
    },
    getComponentName : function() { },
    start : function() { },
    stop : function() {},
    doSomething : function() { … }
}
var consumer = {
    configure : function(hub, conf) {
        hub.requireService({
            component: this,
            contract: myService,
            field: "svc"
        });
    },
    getComponentName : function() { },
    start : function() {},
    stop : function() {},
    work : function() {
        this.svc.doSomething();
    }
}
var consumer = {
    configure : function(hub, conf) {
        hub.requireService({
            component: this,
            contract: myService,
            field: "svc"
        });
    },
    getComponentName : function() { },
    start : function() {},
    stop : function() {},
    work : function() {

    }
        this.svc.doSomething();          Proxy
}
events
var publisher = {
    configure : function(hub, conf) {}
    getComponentName : function() { },
    start : function() {},
    stop : function() {},
    work : function() {
        this.hub.publish(this, "my/topic",
        event);
    }
}
var receiver = {
    configure : function(hub, conf) {
        hub.subscribe(this, "my/(.)*?",
        this.receive);
    },
    getComponentName : function() { },
    start : function() {},
    stop : function() {},
    receive: function(event) { }
}
require.js/node.js
                     Composition


  Modularize your
    JavaScript
                      Standalone
Configurability
h bu
              Stop hacking,
             Start composing


http://nano-project.github.com/h-ubu/snapshot/

h-ubu : CDI in JavaScript

  • 1.
    Group h-ubu CDI in JavaScript Clement Escoffier
  • 4.
    How do wedo that in Java ?
  • 6.
  • 7.
  • 8.
  • 9.
    What do wehave in JavaScript ?
  • 10.
    Module Patterns + - Fix visibility A bit complex No interfaces
  • 11.
    Module loaders + - Avoid <script> Hard-coded Transitive dependencies Reuse
  • 12.
    MVC / MVVM + - Code Pushing organization the limits UI Bindings
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
    var component ={ configure : function(hub, conf) { }, getComponentName : function() { }, start : function() { }, stop : function() {} }; hub .registerComponent(component) .start()
  • 18.
  • 19.
    var myService= { doSomething : function() {} }
  • 20.
  • 21.
    services Service Registry 2 – Lookup, 1 - Publication Service Listener 3 - Binding
  • 22.
    Substitutability Loose-coupling Why services ? Testable Dynamic
  • 23.
    var provider ={ configure : function(hub, conf) { hub.provideService({ component: this, contract: myService }); }, getComponentName : function() { }, start : function() { }, stop : function() {}, doSomething : function() { … } }
  • 24.
    var consumer ={ configure : function(hub, conf) { hub.requireService({ component: this, contract: myService, field: "svc" }); }, getComponentName : function() { }, start : function() {}, stop : function() {}, work : function() { this.svc.doSomething(); } }
  • 25.
    var consumer ={ configure : function(hub, conf) { hub.requireService({ component: this, contract: myService, field: "svc" }); }, getComponentName : function() { }, start : function() {}, stop : function() {}, work : function() { } this.svc.doSomething(); Proxy }
  • 26.
  • 27.
    var publisher ={ configure : function(hub, conf) {} getComponentName : function() { }, start : function() {}, stop : function() {}, work : function() { this.hub.publish(this, "my/topic", event); } }
  • 28.
    var receiver ={ configure : function(hub, conf) { hub.subscribe(this, "my/(.)*?", this.receive); }, getComponentName : function() { }, start : function() {}, stop : function() {}, receive: function(event) { } }
  • 29.
    require.js/node.js Composition Modularize your JavaScript Standalone Configurability
  • 30.
    h bu Stop hacking, Start composing http://nano-project.github.com/h-ubu/snapshot/