Component based Approach using Typescript

At the end of September 2016, I started learning Typescript.Being a Javascript Engineer,I can digest the fact that Javascript will be replaced by superset “Typescript” and finally I moved to Typescript.

I used to write javascript and use extensibly some of libraries like jquery and underscore.It have three years journey with Backbone.js with four different projects and the way it is written to use DOM manipulation,I just love it.But as the project size,maintaining codebase becomes an issues and to maintain each and every views life-cycle is an overhead to developers,so most of time i have explicitly write code to maintain life-cycle of a view.Then came Typescript,initially for me,it look like java and I was like “Dude,Am I writing backend code in UI ?”,but as time passed i started liking it and now i prefer typescript more over vanilla javascript.

But why there was a need of migrating towards typescript ?

Answer I found after some days : Components

Ok,Components,but that can be achieved with backbone also,but why typescript?

So,you can still use backbone and write a wrapper over it and extend the base class.Inheritance was missing in vanilla javascript that Typescript filled the gap.

Lets go and have a real use case.As the project size increase it is hard to maintain code-base they are likely chances of code duplication.So there was need of generic things that can be included in file to be use and instrument.For example write a generic view component with strictly typed variables so that the contract is not validated and that component can be used widely to maintain life-cycle of a component.


class BasicView {
/** this is generic component that have basic life cycles of a component

public render(){
}

public preRender(){
}

public destroy(){
}
}

Now,with typescript you can include basic component to every component.


class Component1 extend BasicView{

constructor(options){
super(options);
}

/** over-ride basic view methods in child view

public render(){
/** over-ride render method here in child view */
}
}

With Component base approach,component behave as individual identity that can be plug and plug.Component accepts a set of data and returns a set of data.So writing test cases also become easy with component based approach.

So,if you see frontend end trends for last two decades,the world is moving towards components.It has add-on features as code re-usability easy debugging and neat and clean files.It becomes really very easy to debug and enhance a product feature.The main advantage component based approach gives ,it makes the complete product loosely coupled.So extending it become too easy and migration is smooth.If you look at all recent frontend framework,they exhaustibly use component based approach.

I have now become huge fan of component based design,now any feature that i need to plug in my system,the first thing comes to mind,how i can follow component based approach and make it re-usable at other places.