SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
FEEDBACK
ANGULARJS + TYPESCRIPT AT SERENYTICS
TypeScript meetup #2 - Paris
2015-06-10
Adrien Chauve
CTO
@adrienchauve
@Serenytics
DISCLAIMER
I'm not a TypeScript expert, nor an AngularJS expert!
But it's better if you know some to follow this talk ;-)
CONTENTS
1.
2.
3.
4.
What we do: Dashboards and Widgets
Why moving to TypeScript?
Angular + TypeScript: HowTo?
The Good, the Bad and the Ugly
1. WHAT WE DO: DASHBOARDS AND WIDGETS
1. WHAT WE DO: DASHBOARDS AND WIDGETS
Year -- All -- Product -- All -- Country -- All --
 13
 $1,034
 $339
1. WHAT WE DO: DASHBOARDS AND WIDGETS
Initial question:
we use AngularJS with lots of different widgets
how to reuse as much code as possible?
while still being able to tune each widget appearance
Solutions:
Service: not enough (factorize logic but not UI interactions)
Single generic directive: single template problem
Directive composition: a generic base directive plus several
small directives to adapt the template and behavior
TypeScript to the rescue, and much much more!
2. WHY MOVING TO TYPESCRIPT?
2. WHY MOVING TO TYPESCRIPT? (1/2)
Potential good solution to factorize our code (more on that
later)
All the goodness of ES6 (classes, fat arrow, template
strings, soon async/await, ...), plus:
statically typed
automatic feedback while developing (think gulp/grunt
watch)
interfaces! description of complex types (e.g. widget
data model) available in a single place and not spread
around the code (Angular is really persmissive for
models)
2. WHY MOVING TO TYPESCRIPT? (2/2)
It's just a Javascript superset, so the migration can be
incremental and smooth, no need to rewrite the app from
scratch
really easy integration with Angular (even if a little scary at
first)
forces to use classes, and then better organize the code
(again Angular is really permissive)
Angular2 is written in TypeScript: Google + Microsoft are
now supporting it
3. ANGULAR + TYPESCRIPT: HOWTO?
3. ANGULAR + TYPESCRIPT: THE BASICS
Controller
Service
Directive
3. ANGULAR + TYPESCRIPT: THE BASICS - CONTROLLERS
Using ControllerAs syntax, a controller is just a Class
angular
.module('my-lib')
.controller('LoginController', LoginController);
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'mylib/auth/login.template.html',
controller: 'LoginController',
controllerAs: 'vm'
})
3. ANGULAR + TYPESCRIPT: THE BASICS - CONTROLLERS
Example in ES5:
var LoginController = (function () {
function LoginController(loginService, $state) {
this.loginService = loginService;
this.$state = $state;
this.invalidCredentials = false;
if (loginService.isLogged) {
$state.transitionTo('home');
}
}
LoginController.prototype.login = function () {
var _this = this;
this.invalidCredentials = false;
this.loginService.loginWithCrendentials(this.email, this.password)
.catch(function () {
_this.invalidCredentials = true;
});
};
return LoginController;
})();
3. ANGULAR + TYPESCRIPT: THE BASICS - CONTROLLERS
Example in TypeScript: lots of goodness in it
class LoginController {
invalidCredentials = false;
email: string;
password: string;
constructor(private loginService: ILoginService,
private $state: angular.ui.IStateService) {
if (loginMgr2.isLogged) {
$state.transitionTo('home');
}
}
login () {
this.invalidCredentials = false;
this.loginService.loginWithCrendentials(this.email, this.password)
.catch(() => {
this.invalidCredentials = true;
});
}
}
3. ANGULAR + TYPESCRIPT: THE BASICS - SERVICES
Just like Controllers:
class LoginService {
constructor(private Restangular: restangular.IService) {
}
loginWithCrendentials (email: string, password: string) {
return this.Restangular.one('api/token')
.then((apiData) => {
// ... save token
// ... transition to 'home' state
});
}
}
angular
.module('my-lib')
.service(loginService, LoginService);
3. ANGULAR + TYPESCRIPT: THE BASICS - DIRECTIVES
interface IWidgetDirectiveScope extends ng.IScope {
widgetModel: IWidgetModel;
}
class WidgetDirective {
scope = {
widgetModel: '=',
};
restrict = 'E';
replace = true;
controllerAs = 'vm'
templateUrl = 'components/widgets/widget.directive.html';
controller = WidgetController;
link = (scope: IWidgetDirectiveScope,
element: ng.IAugmentedJQuery,
attrs: ng.IAttributes,
controller: WidgetController) => {
// ...
}
}
angular.module('my-lib').directive('my-widget', () => {
return new WidgetDirective();
});
3. ANGULAR + TYPESCRIPT: EVEN MORE!
ok Angular + TypeScript is cool, but what about code reuse
and our initial question?
Lots of common behavior between
table widget / value widget (= single cell table)
all chart widgets (pie chart, bar chart, curve chart, ...)
3. ANGULAR + TYPESCRIPT: REUSE CODE!
Different ways:
keep the same controller, adapt the template, 2 directives
for the same price!
inherit base controller to inherit basic behavior exposed to
the view (think Mixins when available)
refresh state (reload data from API)
error handling
global data filtering
data export
implement models (e.g. Widgets) as classes completely
outside of Angular's world
3. ANGULAR + TYPESCRIPT: OUR SOLUTION FOR CODE REUSE
keep directives small and simple, and have several if
needed
each customized with its own template
with possibly one base directive to factorize $scope
features and simple properties (replace, ControllerAs, ...)
one base controller and several inherited controllers as
needed
pure TypeScript Widget classes without any Angular
dependency (model/business logic)
4. THE GOOD, THE BAD AND THE UGLY
4. ANGULAR + TYPESCRIPT: THE GOOD PARTS
easy integration with Angular, especially with ControllerAs
since 1.2
even encourage to use best practises for Angular 2
(ControllerAs => Components)
incremental migration (superset + gradual typing with any)
type infos, type inference and all the good that comes with
it
Interfaces: all the model in one place!
Good debugging experience using source maps with
Chrome
4. ANGULAR + TYPESCRIPT: THE BAD PARTS (1/2)
using 3rd party libraries (missing or outdated typed
definitions): but not such a great problem
dev environment a little more complex (gulp, tsc, tslint,
tsd): actually not so much pain
a little more work sometimes (adding types, directives
more verbose)
4. ANGULAR + TYPESCRIPT: THE BAD PARTS (2/2)
Dealing with class hierarchies: compromise between testability and verbosity
class BaseWidgetController {
private _data: IData;
constructor(private globalFilterService: GlobalFilterService /* other depende
filterData () { return this.globalFilterService.applyFilters(this._data); }
}
class TableWidgetController extends BaseWidgetController {
constructor(private globalFilterService: GlobalFilterService /* other depende
super(globalFilterService, ....);
}
}
/* less verbose alternative - dangerous */
class GlobalFilterService {
/* WARNING: bypass Angular DI and make testing more complex */
static instance() {
angular.element(document.body).injector().get('globalFilterService'
}
applyFilters(...) {...}
}
class BaseWidgetController {
private _data: IData;
constructor() {}
filterData () { return GlobalFilterService.instance().applyFilters(this
}
4. ANGULAR + TYPESCRIPT: UGLY PARTS?
Not really... or maybe
when coding e2e tests with Protractor + TypeScript:
incompatible Promises types
// selenimum-webdriver type declaration
interface IThenable<T> {
then<R>(opt_callback?: (value: T) => Promise<R>, opt_errback?: (error:
then<R>(opt_callback?: (value: T) => R, opt_errback?: (error: any) => any): P
}
// vs. ES6 type declaration
interface Thenable<R> {
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error:
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error:
}
Good luck if you use nodejs with
Q.denodeify or Bluebird.promisify
TOWARDS ANGULAR 2.0: ANGULAR IN TYPESCRIPT
If you:
have a growing project in Angular 1.X
want to invest on it for the next couple of years
Do you a favor, go for TypeScript!
Congrats! you'll be half way through the migration to
Angular2!
Angular 2: everything becomes a TypeScript class with
annotations (Component, Directive)
REFERENCES
Course
@ Pluralsight
by @Foxandxss
by @john_papa
Using TypeScript for Large AngularJS Applications
Why Will Angular 2 Rock?
Angular style guide
TypeScript Roadmap
QUESTIONS?
Want to work with us at Serenytics?
Interested by Analytics, BI and Startups?
Passionate about Angular and TypeScript? Love Python?
Come and see me, we're looking for an amazing dev /
startuper!
Or contact me at adrien.chauve@serenytics.com

Mais conteúdo relacionado

Mais procurados

Automated Xcode 7 UI Testing
Automated Xcode 7 UI TestingAutomated Xcode 7 UI Testing
Automated Xcode 7 UI TestingJouni Miettunen
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Naveen Pete
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariSurekha Gadkari
 
JSF Custom Components
JSF Custom ComponentsJSF Custom Components
JSF Custom ComponentsMichael Fons
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginnersImran Qasim
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript Rohit Bishnoi
 
Android training day 1
Android training day 1Android training day 1
Android training day 1Vivek Bhusal
 
Xcode 7 UI Testing - Xcake Dublin, October 2015
Xcode 7 UI Testing - Xcake Dublin, October 2015Xcode 7 UI Testing - Xcake Dublin, October 2015
Xcode 7 UI Testing - Xcake Dublin, October 2015roland99
 
What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0Michael Fons
 
Angular 1.x in action now
Angular 1.x in action nowAngular 1.x in action now
Angular 1.x in action nowGDG Odessa
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next FrameworkCommit University
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Codemotion
 
Angular Mini-Challenges
Angular Mini-ChallengesAngular Mini-Challenges
Angular Mini-ChallengesJose Mendez
 
iOS Layout Overview
iOS Layout OverviewiOS Layout Overview
iOS Layout OverviewMake School
 

Mais procurados (20)

Automated Xcode 7 UI Testing
Automated Xcode 7 UI TestingAutomated Xcode 7 UI Testing
Automated Xcode 7 UI Testing
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 
JSF Custom Components
JSF Custom ComponentsJSF Custom Components
JSF Custom Components
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginners
 
5 angularjs features
5 angularjs features5 angularjs features
5 angularjs features
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript
 
Android training day 1
Android training day 1Android training day 1
Android training day 1
 
Xcode 7 UI Testing - Xcake Dublin, October 2015
Xcode 7 UI Testing - Xcake Dublin, October 2015Xcode 7 UI Testing - Xcake Dublin, October 2015
Xcode 7 UI Testing - Xcake Dublin, October 2015
 
Ui 5
Ui   5Ui   5
Ui 5
 
What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0
 
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part2
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part22. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part2
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part2
 
Angular 1.x in action now
Angular 1.x in action nowAngular 1.x in action now
Angular 1.x in action now
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
 
Angular Mini-Challenges
Angular Mini-ChallengesAngular Mini-Challenges
Angular Mini-Challenges
 
From mvc to viper
From mvc to viperFrom mvc to viper
From mvc to viper
 
iOS Layout Overview
iOS Layout OverviewiOS Layout Overview
iOS Layout Overview
 
Angular js
Angular jsAngular js
Angular js
 

Semelhante a Feedback using Angularjs + Typescript at Serenytics

Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersOswald Campesato
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0Michael Vorburger
 
Suite Script 2.0 API Basics
Suite Script 2.0 API BasicsSuite Script 2.0 API Basics
Suite Script 2.0 API BasicsJimmy Butare
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development GuideNitin Giri
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetupAnton Kropp
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular jsAndrew Alpert
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)Jose Manuel Pereira Garcia
 
Models, controllers and views
Models, controllers and viewsModels, controllers and views
Models, controllers and viewspriestc
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs WorkshopRan Wahle
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Knoldus Inc.
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
 
AngularJs Style Guide
AngularJs Style GuideAngularJs Style Guide
AngularJs Style GuideChiew Carol
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Angular Presentation
Angular PresentationAngular Presentation
Angular PresentationAdam Moore
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 

Semelhante a Feedback using Angularjs + Typescript at Serenytics (20)

Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
 
Suite Script 2.0 API Basics
Suite Script 2.0 API BasicsSuite Script 2.0 API Basics
Suite Script 2.0 API Basics
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
AngularJS 1.x training
AngularJS 1.x trainingAngularJS 1.x training
AngularJS 1.x training
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetup
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Models, controllers and views
Models, controllers and viewsModels, controllers and views
Models, controllers and views
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
AngularJs Style Guide
AngularJs Style GuideAngularJs Style Guide
AngularJs Style Guide
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 

Último

SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 

Último (20)

SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 

Feedback using Angularjs + Typescript at Serenytics

  • 1. FEEDBACK ANGULARJS + TYPESCRIPT AT SERENYTICS TypeScript meetup #2 - Paris 2015-06-10 Adrien Chauve CTO @adrienchauve @Serenytics
  • 2. DISCLAIMER I'm not a TypeScript expert, nor an AngularJS expert! But it's better if you know some to follow this talk ;-)
  • 3. CONTENTS 1. 2. 3. 4. What we do: Dashboards and Widgets Why moving to TypeScript? Angular + TypeScript: HowTo? The Good, the Bad and the Ugly
  • 4. 1. WHAT WE DO: DASHBOARDS AND WIDGETS
  • 5. 1. WHAT WE DO: DASHBOARDS AND WIDGETS Year -- All -- Product -- All -- Country -- All --  13  $1,034  $339
  • 6. 1. WHAT WE DO: DASHBOARDS AND WIDGETS Initial question: we use AngularJS with lots of different widgets how to reuse as much code as possible? while still being able to tune each widget appearance Solutions: Service: not enough (factorize logic but not UI interactions) Single generic directive: single template problem Directive composition: a generic base directive plus several small directives to adapt the template and behavior TypeScript to the rescue, and much much more!
  • 7. 2. WHY MOVING TO TYPESCRIPT?
  • 8. 2. WHY MOVING TO TYPESCRIPT? (1/2) Potential good solution to factorize our code (more on that later) All the goodness of ES6 (classes, fat arrow, template strings, soon async/await, ...), plus: statically typed automatic feedback while developing (think gulp/grunt watch) interfaces! description of complex types (e.g. widget data model) available in a single place and not spread around the code (Angular is really persmissive for models)
  • 9. 2. WHY MOVING TO TYPESCRIPT? (2/2) It's just a Javascript superset, so the migration can be incremental and smooth, no need to rewrite the app from scratch really easy integration with Angular (even if a little scary at first) forces to use classes, and then better organize the code (again Angular is really permissive) Angular2 is written in TypeScript: Google + Microsoft are now supporting it
  • 10. 3. ANGULAR + TYPESCRIPT: HOWTO?
  • 11. 3. ANGULAR + TYPESCRIPT: THE BASICS Controller Service Directive
  • 12. 3. ANGULAR + TYPESCRIPT: THE BASICS - CONTROLLERS Using ControllerAs syntax, a controller is just a Class angular .module('my-lib') .controller('LoginController', LoginController); $stateProvider .state('login', { url: '/login', templateUrl: 'mylib/auth/login.template.html', controller: 'LoginController', controllerAs: 'vm' })
  • 13. 3. ANGULAR + TYPESCRIPT: THE BASICS - CONTROLLERS Example in ES5: var LoginController = (function () { function LoginController(loginService, $state) { this.loginService = loginService; this.$state = $state; this.invalidCredentials = false; if (loginService.isLogged) { $state.transitionTo('home'); } } LoginController.prototype.login = function () { var _this = this; this.invalidCredentials = false; this.loginService.loginWithCrendentials(this.email, this.password) .catch(function () { _this.invalidCredentials = true; }); }; return LoginController; })();
  • 14. 3. ANGULAR + TYPESCRIPT: THE BASICS - CONTROLLERS Example in TypeScript: lots of goodness in it class LoginController { invalidCredentials = false; email: string; password: string; constructor(private loginService: ILoginService, private $state: angular.ui.IStateService) { if (loginMgr2.isLogged) { $state.transitionTo('home'); } } login () { this.invalidCredentials = false; this.loginService.loginWithCrendentials(this.email, this.password) .catch(() => { this.invalidCredentials = true; }); } }
  • 15. 3. ANGULAR + TYPESCRIPT: THE BASICS - SERVICES Just like Controllers: class LoginService { constructor(private Restangular: restangular.IService) { } loginWithCrendentials (email: string, password: string) { return this.Restangular.one('api/token') .then((apiData) => { // ... save token // ... transition to 'home' state }); } } angular .module('my-lib') .service(loginService, LoginService);
  • 16. 3. ANGULAR + TYPESCRIPT: THE BASICS - DIRECTIVES interface IWidgetDirectiveScope extends ng.IScope { widgetModel: IWidgetModel; } class WidgetDirective { scope = { widgetModel: '=', }; restrict = 'E'; replace = true; controllerAs = 'vm' templateUrl = 'components/widgets/widget.directive.html'; controller = WidgetController; link = (scope: IWidgetDirectiveScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, controller: WidgetController) => { // ... } } angular.module('my-lib').directive('my-widget', () => { return new WidgetDirective(); });
  • 17. 3. ANGULAR + TYPESCRIPT: EVEN MORE! ok Angular + TypeScript is cool, but what about code reuse and our initial question? Lots of common behavior between table widget / value widget (= single cell table) all chart widgets (pie chart, bar chart, curve chart, ...)
  • 18. 3. ANGULAR + TYPESCRIPT: REUSE CODE! Different ways: keep the same controller, adapt the template, 2 directives for the same price! inherit base controller to inherit basic behavior exposed to the view (think Mixins when available) refresh state (reload data from API) error handling global data filtering data export implement models (e.g. Widgets) as classes completely outside of Angular's world
  • 19. 3. ANGULAR + TYPESCRIPT: OUR SOLUTION FOR CODE REUSE keep directives small and simple, and have several if needed each customized with its own template with possibly one base directive to factorize $scope features and simple properties (replace, ControllerAs, ...) one base controller and several inherited controllers as needed pure TypeScript Widget classes without any Angular dependency (model/business logic)
  • 20. 4. THE GOOD, THE BAD AND THE UGLY
  • 21. 4. ANGULAR + TYPESCRIPT: THE GOOD PARTS easy integration with Angular, especially with ControllerAs since 1.2 even encourage to use best practises for Angular 2 (ControllerAs => Components) incremental migration (superset + gradual typing with any) type infos, type inference and all the good that comes with it Interfaces: all the model in one place! Good debugging experience using source maps with Chrome
  • 22. 4. ANGULAR + TYPESCRIPT: THE BAD PARTS (1/2) using 3rd party libraries (missing or outdated typed definitions): but not such a great problem dev environment a little more complex (gulp, tsc, tslint, tsd): actually not so much pain a little more work sometimes (adding types, directives more verbose)
  • 23. 4. ANGULAR + TYPESCRIPT: THE BAD PARTS (2/2) Dealing with class hierarchies: compromise between testability and verbosity class BaseWidgetController { private _data: IData; constructor(private globalFilterService: GlobalFilterService /* other depende filterData () { return this.globalFilterService.applyFilters(this._data); } } class TableWidgetController extends BaseWidgetController { constructor(private globalFilterService: GlobalFilterService /* other depende super(globalFilterService, ....); } } /* less verbose alternative - dangerous */ class GlobalFilterService { /* WARNING: bypass Angular DI and make testing more complex */ static instance() { angular.element(document.body).injector().get('globalFilterService' } applyFilters(...) {...} } class BaseWidgetController { private _data: IData;
  • 24. constructor() {} filterData () { return GlobalFilterService.instance().applyFilters(this }
  • 25. 4. ANGULAR + TYPESCRIPT: UGLY PARTS? Not really... or maybe when coding e2e tests with Protractor + TypeScript: incompatible Promises types // selenimum-webdriver type declaration interface IThenable<T> { then<R>(opt_callback?: (value: T) => Promise<R>, opt_errback?: (error: then<R>(opt_callback?: (value: T) => R, opt_errback?: (error: any) => any): P } // vs. ES6 type declaration interface Thenable<R> { then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: } Good luck if you use nodejs with Q.denodeify or Bluebird.promisify
  • 26. TOWARDS ANGULAR 2.0: ANGULAR IN TYPESCRIPT If you: have a growing project in Angular 1.X want to invest on it for the next couple of years Do you a favor, go for TypeScript! Congrats! you'll be half way through the migration to Angular2! Angular 2: everything becomes a TypeScript class with annotations (Component, Directive)
  • 27. REFERENCES Course @ Pluralsight by @Foxandxss by @john_papa Using TypeScript for Large AngularJS Applications Why Will Angular 2 Rock? Angular style guide TypeScript Roadmap
  • 28. QUESTIONS? Want to work with us at Serenytics? Interested by Analytics, BI and Startups? Passionate about Angular and TypeScript? Love Python? Come and see me, we're looking for an amazing dev / startuper! Or contact me at adrien.chauve@serenytics.com