Presentation for the session held on CodeCamp Macedonia 2013.
Last year we saw what TypeScript promises. Now a year later, it's time to see whether it delivers.
In my opinion, it does, and when used with knockout.js it does so with a punch. The TypeScript generics mesh beautifully with knockout's observables and result in a dynamic, declarative, and type-safe code base, that's easy to work with.
The presentation also covers a note of the future of the C# language, based on information for proposed language features.
The code shown can be seen on https://github.com/sweko/tko
The presentation is live on http://monaco-swekster.azurewebsites.net/Roles.tko.html
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
TKO - Awesomeness using TypeScript with knockout.js
1.
2. TKO
Knocking it out of the ball park with
TypeScript and knockout.js
Wekoslav Stefanovski
Senior Developer, Seavus
swekster@gmail.com
3.
4. Agenda
A little bit of history
A little bit of present
Why is TypeScript needed? How is it used?
Why is knockout needed? How is it used?
Why are they great together?
Bonus Topic: Surprise
5. A little bit of history
What is this thing called Javascript???
Prototype-based dynamic scripting language
Build in Netscape in 1995, initially focused on
non-professional developers.
Standardized as ECMAScript (in 1999)
Still the version most browsers / developers use.
6. A little bit of history, part II
What is this thing called DOM???
Even worse consistency than javascript.
Latest specification is from 2004, a.k.a. Internet Prehistory
jQuery (and friends) to the rescue
Still, it’s not a traditional programming object model
– Hard to manipulate
– Hard to automate
7. A little bit of present
The rise of the Single-Page Application
Heavy client logic, getting heavier
Stateless web is dead and more alive than ever
The attack of the APIs and services
Ongoing M/V separation
8. Why is TypeScript needed
Javascript’s got 99 problems but types ain’t one
– Variable hoisting – no implicit global variables in typescript
– Truthy and falsy values – only booleans allowed in boolean
checks
– No explicit includes – has explicit references and dependencies
– The this parameter can be actually that - lexical scoping
ECMAScript 6 standard specification is a long way off
– TypeScript type definition syntax is aligned with ECMAScript 6
9. Why is knockout.js needed?
Declarative bindings
Automatic UI updating
Dependency tracking
Templating
No (or very little) code mixed with html
No html mixed with code
10. Why are they great together?
Typescript generics add strictness to knockout
Encourages correct usage
Better sense of confidence in the code
Improved readability
Improved testability
11.
12.
13. The Future of C# - C# 6.0
1. Primary Constructors
Before
After
public class Point
{
private int x, y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
public class Point(int x, int y)
{
private int x, y;
}
14. The Future of C# - C# 6.0
2. Readonly auto properties
Before
After
public readonly int x = 3;
public int X
{
get
{
return x
}
}
public int X {get; } = 3;
15. The Future of C# - C# 6.0
3. Static type using statements
Before
public double A
{
get { return Math.Round(Math.Sqrt(Math.Abs(someValue))); }
}
After
using System.Math;
public double A
{
get { return Round(Sqrt(Abs(someValue))); }
}
16. The Future of C# - C# 6.0
4. Property Expressions
Before
public double Distance
{
get { return Math.Sqrt(X * X + Y * Y); }
}
After
public double Distance => Math.Sqrt(X * X + Y * Y);
17. The Future of C# - C# 6.0
5. Method Expressions
Before
public double MoveRight(int dx)
{
return new Point(X + dx, Y);
}
After
public double MoveRight(int dx) => new Point(X + dx, Y);
18. The Future of C# - C# 6.0
6. Params for enumerables
Before
Do(someEnumerable.ToArray());
...
public void Do(params int[] values) { ... }
After
Do(someEnum);
...
public void Do(params IEnumerable<int> points) { ... }
19. The Future of C# - C# 6.0
7. Inline declarations for out params
Before
After
int x;
int.TryParse("123", out x);
int.TryParse("123", out int x);
20. The Future of C# - C# 6.0
8. Monadic null checking
Before
if (points == null)
return -1;
var next = points.FirstOrDefault();
if ((next == null) || (next.X == null))
return -1;
return next.X;
After
return points?.FirstOrDefault()?.X ?? -1;
21. The Future of C# - C# 6.0
9. Constructor type parameter inference
Before
var x = MyClass.Create(1, "X");
...
public static MyClass
{
public MyClass<T1, T2> Create<T1, T2>(T1 a, T2 b)
{
return new MyClass<T1, T2>(a, b);
}
}
After
var x = new MyClass(1, "X");
22.
23. • Complete electronic evaluation forms on the
computers in the hall and enter to win!
– Infragistics Ultimate
– Telerik DevCraft
– JetBrains .NET tools
– Semos training vouchers
– Pluralsight subscriptions
– and many more…