Firebrick JS - Controllers

simple example with controllers in firebrick

by smasala

HTML

<script src="http://knockoutjs.com/downloads/knockout-3.2.0.js"></script>
<script src="https://cdn.rawgit.com/smasala/firebrick/0e0b8ba6/dist/firebrick.js"></script>
<a href="#">A Link</a>

JavaScript

//Define a Controller
Firebrick.create("MyApp.MyController1", {
    extend:"Firebrick.controller.Base",
    init:function(){
        this.app.on({
            "a":{
                click:function(){
                    //jquery event arguments
                    console.info("in the controller", arguments);
                    console.info("lets fire an event application wide");
                    //fire events with unlimited arguments
                    Firebrick.fireEvent("somethingwasclicked", 123);
                }
            }
        });
        //calls init of Firebrick.controller.Base (important)
        this.callParent();
    }
});


//Define a Controller
Firebrick.create("MyApp.MyController2", {
    extend:"Firebrick.controller.Base",
    init:function(){
        this.app.listeners({
            //first argument is always event object (in this case FB event obj)
            "somethingwasclicked": this.catch,
            scope:this
        });
        //calls init of Firebrick.controller.Base (important)
        this.callParent();
    },
    
    catch: function(event, data){
        console.info("somethingwasclicked -> MyController2", data);   
    }
});