(A.K.A learning JS, Typescript, Async programming and Git so you can survive this term)
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
Plain JS
Plain JS
Typescript
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
class Greeter {
greeting: string;
constructor (message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
Typescript
interface Thing {
[key: string]: number | string;
}
Interfaces are great and you should use them!
Typescript
Transpiler
Javascript
Typescript
Transpiler
Javascript
Therefore, you will see javascript (.js) files, but you should work on the typescript (.ts) files
let list = [4, 5, 6];
for (let i in list) {
console.log(i); // "0", "1", "2",
}
let list = [4, 5, 6];
for (let i of list) {
console.log(i); // "4", "5", "6"
}
For ... in
For ... of
(a.k.a reason why most students failed the deliverable. Really. )
(a.k.a reason why most students failed the deliverable. Really. )
We can change this.
let GetNumberFromAPI = function () {
return Math.round(Math.random()*10) + 1;
}
function GetEvenNumberPromise(): Promise<number> {
return new Promise(function (fulfill, reject) {
var n = GetNumberFromAPI(); // remote code being executed, it takes a while
if (n % 2 === 0) {
fulfill(n);
} else {
reject(n);
}
});
}
let ItIsEven = function(EvenNumber: number) {
console.log("It is even! Number is: ", EvenNumber);
}
let ItIsOdd = function(OddNumber: number) {
console.log("It is odd! Number is: ", OddNumber);
}
let promise = GetEvenNumberPromise();
// First argument is a function that handles the success
// Second argument is a function that handles the rejection
promise.then(ItIsEven, ItIsOdd)
.catch(//them all)
console.log("This is going to be printed first");
function GetTwoNumbers(): Promise[] {
let evenNumbersPromises: Promise[] = [];
for (let i=0; i<2; i++) {
evenNumbersPromises.push(GetEvenNumberPromise())
}
console.log('list of promises is ', evenNumbersPromises)
return evenNumbersPromises
}
let evenNumbers = GetTwoNumbers();
let AllEven = function(evenNums: number[]){
console.log('All are even! They are; ', evenNums)
}
let AllNotEven = function(evenNums: number[]){
console.log('All are not even... Rejected instance is; ', evenNums)
}
// evenNumbers should be an 'iterable', you pass an array of reject/fulfills
Promise.all(evenNumbers).then(AllEven, AllNotEven)
(A.K.A how to collaboratively manage your code and not feel like hurting your teammate's feelings )
Github's servers
Your machine
git clone $YOUR_REPOSITORY_URL
git pull origin master
// In case you already have the repository
// locally, but it's not up to date
git add --all
git commit -m "my neat commit"
git commit -m "my neat commit"
git push origin master
git push origin master
https://www.atlassian.com/git/tutorials/what-is-version-control
http://rogerdudler.github.io/git-guide/