Instantly share code, notes, and snippets.

# viciouslabs

• Sort options
Created Nov 23, 2017
RxJS: Promise Observable Similarity
View promise_observable_similarity.js
 // 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) {
Created Nov 23, 2017
RxJS: Stream Completion
View stream_completion.js
 // 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() {
Created Nov 23, 2017
Array vs Stream
View array_stream.js
 // 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}`))
Last active Nov 22, 2017
Play around with RxJS: http://jsbin.com/xumejor/edit?js
View rxjs_into.js
 /** * 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
Last active Oct 15, 2017
MobX for those who can't get over their ex, Redux
View mobx-bringing-back-immutability.js
 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 }
You can’t perform that action at this time.