Skip to content

Emerjoin/Hi-Hooks

Repository files navigation

Hi-Framework Hooks

API to enable Hooks for Hi-Framework

Changes-log

  • beforeRun hook now receives one argument : the hi-framework angular module object - hook must be used to set configuration on the hi app module object.
  • new hook: setupApp - hook to set configurations on the app module object

Maven dependency

    <dependencies>
        <dependency>
            <groupId>org.emerjoin</groupId>
            <artifactId>Hi-Framework-Hooks</artifactId>
            <version>2.1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

Including hooks to template

    <script src="webroot/emerjoin/hf-hooks.min.js"></script>

BeforeRun hook

This hook is executed before the angular application is run. You can add as many hooks as you need.

    
    AppHooks.beforeRun(function(hiAppModule){
        
        hiAppModule.config(function(){
                    
            //do something here
                    
        });
                
        hiAppModule.run(function(){
                    
            //Do more here
                    
        });
    
    });
    

BeforeView hook

This hook is executed before a specific view controller gets executed. This hook allows to transform the view's $scope object and to add objects to be resolved upon dependencies injection.

Transform scope

Allows to transform the view's $scope object.

Setting the hook

    AppHooks.beforeView(function(before){
        
        //The $scope object is bound to "this" keyword
        before.transform(function(){
        
            //This property is being added to the view's $scope
            this.car = {brand:"Toyota",model:"Rav4"};
        
        },"controler/action");
    
    });

Accessing the object set by the transformer

    Hi.view(function($scope){
    
        console.log($scope.car.brand); //Toyota
    
    });
    

Inject objects

Allows to add objects to be resolved during dependency injection

Setting the hook

    AppHooks.beforeView(function(before){
        
      
        //This function is meant to add objects to be resolved during dependency injection 
        before.inject(function(){
            
            
            this.person = {name:"Mario",surname:"Junior"};
           
        
        });
        
    
    },"controler/action");

Accessing the object set to injection

    Hi.view(function($scope,person){
    
         console.log(person.name);//Mario
        
    });

Global View Hook

Invoke the AppHooks.beforeView function without passing the second parameter (view url).

    AppHooks.beforeView(function(before){
        
        //Do something in here
    
    });

Setup app Hook

Hook used to set configuration on the app module object

    AppHooks.setupApp(function(appModule){
        
        appModule.config(function(){
            
            //do something here
            
        });
        
        appModule.run(function(){
            
            //Do more here
            
        });
    
    });