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
class Message { | |
@observable message = "Hello world" | |
// fictional example, if author is immutable, we just need to store a reference and shouldn't turn it into a mutable, observable object | |
@observable.ref author = null | |
} |
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
/** | |
* Solving the problem: | |
* In a circular race of 1200 m length, A and B start with speeds of 18kmph and 27 kmph starting | |
* at the same time from the same point. When will they meet for the first time at the starting | |
* point when running in the same direction? | |
*/ | |
// converts kmph to mps | |
function convertToMetersPerSecond(speedInKmph) { | |
return (1000/3600) * speedInKmph |
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
// simple array | |
const arr = [{ x: 1, y: 4 }, { x: 20.2, y: 40.4 }, { x: 130.2, y: 240.1 }] | |
// stream of mouse position looks similar | |
const stream = [{ x: 1, y: 4 }, { x: 20.2, y: 40.4 }, { x: 130.2, y: 240.1 }] | |
// simply priting all array items | |
Rx.Observable.fromArray(arr) | |
.subscribe(x => console.log(`Array item: ${x.x}, ${x.y}`)) |
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
// An array stream is a stream that completes | |
Rx.Observable.fromArray([1,2,3,4]) | |
.subscribe( | |
function next(input) { | |
console.log('Received event data', input) | |
}, | |
function error(err) { | |
consle.log('Log error', err) | |
}, | |
function complete() { |
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
// example of a promise | |
const deferred = new Promise((resolve, reject) => { | |
setTimeout(function() { | |
resolve('Promise resolved.') | |
}, 2000) | |
}) | |
deferred.then(function resolved(data) { | |
console.log(data) | |
}, function rejected(err) { |