Prabhu Sunderaraman

Fullstack Engineer, Programmer, Writer, Trainer

prabhu.bits@gmail.com,     GitHub     Youtube     LinkedIn
  • Home
  • Profile
  • Books
  • Reading List
Browsing: / Home
Shortlink

Here Cometh Ext JS 5 – III

By Prabhu Sunderaraman on December 12, 2014 in Ext JS

View Controllers

Like the ViewModel, Ext JS 5 introduces a ViewController class. The ViewController class can be used instead of the traditional Controller class. The Controller classes manage the views and bind the events with the views. This can become a bit tedious if the application grows as a single view can be managed by multiple controllers and a single controller can also manage multiple views.
ViewControllers solve this problem by reversing the role played by the controllers.

  • The View components will specify the ViewControllers that will manage them.
  • The View components define a reference that the ViewControllers can use to handle them

Let’s create a textfield and a button. The button’s click event will be handled by a ViewController. The ViewController accesses the textfield using the reference and fetches the entered value.

Ext.create('Ext.panel.Panel', {     
  controller : "signup",     
  items : [     	
   {
      xtype : "textfield",     		
      emptyText : "User Name",     		
      reference : "username"     	
   },
   { 
      xtype : "button",     		
      text : "Sign up",     		
      listeners : {     			
        click : "onSignupButtonClicked"
      }
   } 
 ] 
});

The Panel is linked to a controller called signup which is a ViewController that we’ll define later. The User Name textfield has a reference username that the ViewController will use. The click event of the button is handled by the onSignupButtonClicked function defined in the ViewController. And here’s the ViewController.

Ext.define('SignupController', {     
   extend: 'Ext.app.ViewController', 	
   alias: 'controller.signup', 	
   onSignupButtonClicked : function(){ 		
     var userName = this.lookupReference("username"); 		
     console.log(userName.getValue()); 	
   } 
}); 

You can read more about the ViewController in http://docs.sencha.com/extjs/5.0.0/application_architecture/view_controllers.html.

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Here Cometh Ext JS 5 – II

By Prabhu Sunderaraman on December 11, 2014 in Ext JS

Data binding in Ext JS 5

Data binding is a beaten-to-death concept in UI frameworks. You bind the value of a variable to some property of an UI component. Any changes to the value of the variable will result in changes to the UI component and vice versa. Ext JS 5 introduces this concept using a new class called ViewModel. The ViewModel manages the binding between the data and the view components.
Let’s create a simple example to use the ViewModel. We’ll bind password textbox with a ViewModel. Based on the length of the password field we would like to display a tick mark or a cross mark. The tick or cross marks indicate the strength of the password. Figure 1.0 shows the password text box which is empty initially. So you have a cross mark displayed. As you start typing the password and the length of the value reaches five a tick mark appears as shown in Figure 2.0.

03
Figure 1.0: Password textfield with a cross mark by the side
04
Figure 2.0: Password textfield with a tick mark by the side
Let’s define our ViewModel class with the password data and a simple formula to calculate the length of the password.

Ext.define('SignUpViewModel', {     
  extend: 'Ext.app.ViewModel',     
  alias: 'viewmodel.signup',     
  data: {         
   password:"",     
  },     
  formulas : {     	
   passwordlength : function(get){     		
     return get("password").length > 5;    
   }     
  } 
}); 

The SignUpViewModel class contains the password field and passwordlength function that returns a boolean based on the length. We’ll bind the SignUpViewModel with our password textbox like this.

Ext.create('Ext.panel.Panel', {     
  layout : "hbox",     
  title : "Data binding",     
  viewModel: "signup",     
  items : [     	
   {     		
     xtype : "textfield",     		
     inputType : "password",     		
     emptyText : "Password",     		
     bind : {     			
        value : "{password}"     		
     }
   },
   {     		
     xtype : "image",     		
     src : "http://www.clker.com/cliparts/e/3/9/7/1245686792938124914raemi_Check_mark.svg.hi.png",
     height:"80%",width:"2%",     		
     bind : {     			
        hidden : "{!passwordlength}" 
     }
    },     	
    {  
   	xtype : "image",     		
        src : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR_DEG40dmCdNXtY5HRmgaoCbNz1eAgAovSG3uCBYBKSUO_H64S",
        height:"80%",width:"2%",     		
        bind : {     			
          hidden : "{passwordlength}"   
  	}
    } 
  ] 
}); 

As you can notice in the code, the viewmodel property is mapped to the signup ViewModel. The bind property is used to map the value of the textfield with the password data field. The passwordlength formula is bound with the image components.
Though ViewModel is a useful feature, the documentation that talks about the internals of the ViewModel says it’s pretty memory intensive and needs to be used judiciously. With the introduction of this ViewModel Ext JS 5 applications can be built using MVVM(Model-View-ViewModel) architecture as well. So we have now two architectural options to build applications, MVC and MVVM.

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Here cometh Ext JS 5 – I

By Prabhu Sunderaraman on December 9, 2014 in Ext JS

What’s new in Ext JS 5?

Ext JS 5 provides a lot of API changes, architectural options and new features. This version also narrows down the gap with Sencha Touch, the mobile JavaScript library. Some of the new features in Ext JS 5 that we’ll see in the series of articles are:

  • Responsive plugins
  • Data binding
  • View Controllers

These three features were long overdue in Ext JS. A couple of features are already present in a number of JS libraries.

Responsive Plugins

Responsive UI has become a norm in the applications we build today. We want our applications to automatically respond to various devices like tablets, smart phones. Sencha Touch has the profile that is used to handle the responsive UI. But this facility has been introduced in Ext JS 5 in the form of a responsive plugin. Here’s an example where a panel has three buttons. These buttons will be arranged horizantally when the page is viewed in a tablet but will be arranged vertically when viewed in a phone. We can compare the width of the devices and implement this.

Ext.onReady(function(){ 	
  Ext.create("Ext.panel.Panel",{ 		
    renderTo : Ext.getBody(), 		
    plugins : "responsive", 		
    title : "Sample Panel", 		 
    responsiveConfig: { 		     
      'width > 600': { 		        
         layout : { 					
           type:"hbox", 					
           pack : "center" 				
         }
       },
       'width <= 600': { 		        
         layout : { 					
           type:"vbox",
 	   align : "center"
 	 }
       }
    } 	
  }); 
}); 

The Panel has the responsive plugin used and the rules are specified in the responsiveConfig property, where the width is compared. Figure 1.0 shows the panel when viewed in a Nexus 7 tablet using Ripple Emulator. Figure 2.0 shows the panel when viewed in an iPhone.
Buttons arranged horizantally in a tablet
Figure 1.0: Buttons arranged horizontally in a tablet
02
Figure 2.0: Buttons arranged vertically in a phone

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Videos on Scala

By Prabhu Sunderaraman on November 3, 2014 in Scala

Here’s a list of videos on Scala programming language. Have fun!!!

Hello Scala


Data Types and Variables


Functions in Scala – Part I


Functions in Scala – Part II

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Interview with Bruce Tate

By Prabhu Sunderaraman on October 13, 2014 in HealthyCodeMagazine

Chatting with Bruce Tate the author of several books, particularly Seven Languages in Seven Weeks was an unforgettable experience.

bruce

seven

Bruce Tate was in Bangalore last week for a Functional conference. Attended his workshop on Elixir in the morning. Elixir cleared lot of my suspicions about Scala language and yes, opened doors to the new one. It was a very small but fun-to-be-with group writing some Elixir code with Bruce. In the afternoon, Bruce and I had a nice chat about his experience working with several languages and books.

You can read the interview in the november issue of the HealthyCode magazine. It would definitely be an eye-opener for the developers who get married to one programming language in their long career.

Share this on: Mixx Delicious Digg Facebook Twitter
« Previous 1 … 26 27 28 … 64 Next »

Youtube Channel




Categories

  • JavaScript (48)
    • RequireJS (5)
  • Go (44)
  • Golang (44)
  • Ext JS (23)
  • Spring (22)
  • Mobile (21)
  • Scala (20)
    • Play (3)
  • Uncategorized (19)
  • Video Sessions (18)
  • GoG (17)
  • Sencha Touch (16)
  • jQuery (14)
  • Languages (13)
  • Java 8 (12)
  • React JS (11)
  • Kotlin (11)
  • HealthyCodeMagazine (9)
  • Video (9)
  • Objective-C (8)
  • NoSQL (8)
  • Android (7)
  • MongoDB (7)
  • GWT (6)
  • Tools (6)
  • HTML 5 (5)
  • Cloud (5)
  • General (5)
  • Micro services (5)
  • Java (5)
  • Books (4)
  • AWS (4)
  • Software Architecture (4)
  • .NET (3)
  • Elixir (3)
  • Docker (3)
  • Reactive (3)
  • NodeJS (2)
  • RoR (2)
  • Backbone (1)
  • AngularJS (1)

Archives

  • 2020 (49)
  • 2019 (7)
  • 2018 (34)
  • 2017 (15)
  • 2016 (7)
  • 2015 (18)
  • 2014 (31)
  • 2013 (55)
  • 2012 (100)

Search

Subscribe




Copyright © 2025 Prabhu Sunderaraman.

Powered by WordPress and News.