Last active
August 5, 2017 15:59
-
-
Save DaveMBush/9c023a712c293fc28a72418b6bb2699d to your computer and use it in GitHub Desktop.
Explaining Observables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.fromEvent(this.myInput,'change').debounceTime(250).subscribe((event) => | |
/* do something in response to the input field change here */ | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someList = [ | |
{id: 1, firstName: ‘Dave’, lastName: ‘Bush’}, | |
{id: 2, firstName: ‘John’, lastName: ‘Doe’}, | |
… | |
]; | |
newArray = someList.filter(function(item) { | |
return item.lastName.startsWith(‘B’); | |
}.map(function(item) { | |
return {fullName: item.firstName + ‘ ‘ + | |
item.lastName, id: item.id}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.httpClient.get<TypeInfo>('/api/get-data') | |
.subscribe((x: TypeInfo) => /* do something with the data */ ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.httpClient.get<TypeInfo>(‘/api/get-data’) | |
.catch(err: Error => /* do something with the error */) | |
.subscribe((x: TypeInfo) => /* do something with the data */); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.httpClient.get<TypeInfo>(‘/api/get-data’) | |
.retry(3) | |
.catch(err: Error => /* do something with the error */) | |
.subscribe((x: TypeInfo) => /* do something with the data */); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someList = [ | |
{id: 1, firstName: ‘Dave’, lastName: ‘Bush’}, | |
{id: 2, firstName: ‘John’, lastName: ‘Doe’}, | |
… | |
]; | |
var i; | |
var newArray = []; | |
for(i = 0; i < someList.length; i++) { | |
var item = someList[i]; | |
newArray.push({fullName: item.firstName + ‘ ‘ + | |
item.lastName, id: item.id}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someList = [ | |
{id: 1, firstName: ‘Dave’, lastName: ‘Bush’}, | |
{id: 2, firstName: ‘John’, lastName: ‘Doe’}, | |
… | |
]; | |
var i; | |
var newArray = []; | |
for(i = 0; i < someList.length; i++) { | |
var item = someList[i]; | |
if(item.lastName.startsWith(‘B’) { | |
newArray.push(item); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someList = [ | |
{id: 1, firstName: ‘Dave’, lastName: ‘Bush’}, | |
{id: 2, firstName: ‘John’, lastName: ‘Doe’}, | |
… | |
]; | |
var newArray = []; | |
someList.map(function(item) { | |
if(item.lastName.startsWith(‘B’)) { | |
newArray.push({fullName: item.firstName + ‘ ‘ + | |
item.lastName, id: item.id}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someList = [ | |
{id: 1, firstName: ‘Dave’, lastName: ‘Bush’}, | |
{id: 2, firstName: ‘John’, lastName: ‘Doe’}, | |
… | |
]; | |
newArray = someList.filter(function(item) { | |
return item.lastName.startsWith(‘B’); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someList = [ | |
{id: 1, firstName: ‘Dave’, lastName: ‘Bush’}, | |
{id: 2, firstName: ‘John’, lastName: ‘Doe’}, | |
… | |
]; | |
var newArray = someList.map(function(item) { | |
return {fullName: item.firstName + ‘ ‘ + | |
item.lastName, id: item.id}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numbers = [1, 2, 3]; | |
var total = numbers.reduce(function(sum, item) { | |
return sum + item; | |
}, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment