Upload
michael-haberman
View
141
Download
3
Embed Size (px)
Citation preview
The web trend • Web has became very popular
• Going from .net under the roof of Microsoft to the open web under the roof of the community it’s a huge leap.
How can we leverage our knowledge? • MVVM (data-‐binding, commanding and etc..)
• OOP
• The way we tackle requirements
JS & HTML differences • Many libraries
• Many IDEs
• Open source – community support
• It doesn’t compile
• Doesn’t have MVVM by nature
• OOP? What is that?
Type Script – lets make it compile! • Compiles your Javascript Code!!
• Compile time errors
• Intellisense
• Type validation
TypeScript -‐ OOP • Classes • Inheritance
• Access Modifiers
• Interfaces
• Overriding
• Properties
• Generics
TypeScript -‐ class
export class Animal { static IDCounter = 0; public ID : number; public Name : string; constructor(name : string, age? : number ){ this.Name = name; } public Sleep() : boolean{ return true; } }
TypeScript -‐ Inheritance
export class Dog extents Animal{ Bark(volume : number) : bool{ return false; } }
TypeScript -‐ Access Modifiers
export class Dog extents Animal{ public TaliLength : number;
private _id : string; protected type : string; // available from ts 1.3
}
TypeScript -‐ Interfaces
Interface IFlyable{
fly(height : number) : void;
}
Function(flyable : Iflyable){ flyable.fly(“123123”) // compiler error }
TypeScript -‐ Overriding
export class FlyingAnimal extends Animal{ public Fly() : number{ alert('7'); return 7; } }
export class Duck extends AquaticAnimal{ Fly(){ alert('I am flying!!'); } }
TypeScript -‐ Properties
_age : number;
get Age : number {Return _age;} set Age(value : number) { if(value > 0) {this._age = value;} }
TypeScript with other frameworks • *.d.ts file – contains all the definition of the framework
• https://github.com/borisyankov/DefinitelyTyped
MVVM Features • Data Binding • Converter • Mode
• INotifyPropertyChanged
• Command • Passing a parameter
• Context Binding
Setting DataContext Knockout
C#
var vm = new MySampleAPP.MainViewModel()
ko.applyBindings(vm);
DataContext = new MainViewModel();
Binding an element Knockout
XAML
<input type="text" data-‐bind="value: FirstName"/>
<TextBlock Text="{Binding FirstName}"/>
Visibility bound to ViewModel Knockout
XAML
data-‐bind="if: HasLoggedinUser”
data-‐bind="visible: Status() == 'Working'"
Visibility="{Binding HasLoggedinUser, Converter={StaticResource Converter}}"/>
Commands Knockout
XAML
<input type="button" data-‐bind="click: ChangeUser, valueUpdate:'input'"/>
<Button Command="{Binding ChangeUser}"/>
Iterate through collections -‐ XAML
<ItemsControl ItemsSource="{Binding Collection}" >
<TextBlock Text="{Binding Name}"/>
</ItemsControl>
Iterate thought collections -‐ Knockout
<table data-‐bind="if: HasLoggedinUser">
<tbody data-‐bind="foreach: Employees">
<tr>
<td><span data-‐bind="text: Name"></span></td>
</tr>
</tbody>
</table>
New style converters
self.SalaryState = ko.computed(() => {
…
return “red”; });
<span data-‐bind="text: Salary, style: { color: SalaryState()}" ></span>
Knockout context binding • Similar to relative source or element binding: • $parent -‐ $parent[indexer] • $root • $element
What next? • Go home and start develop in the web environment
• Use your OOP knowledge using TypeScript
• Try other frameworks also (Angular, backbone, ember)
• They all work with TypeScript