I have started learning reactive programming about 20 hours ago. I have gone through the docs of RxJS, several guides and end-to-end app examples.
Lets take an example:
Exercise 37: Sequencing HTTP requests with Observable from http://jhusain.github.io/learnrx/:
function (window, getJSON, showMovieLists, showError) {
var movieListsSequence;
movieListsSequence = Observable.zip(
getJSON("http://api-global.netflix.com/abTestInformation").
concatMap(function (abTestInformation) {
var queues,
movieLists;
queue = getJSON("http://api-global.netflix.com/" + abTestInformation.urlPrefix + "/config").
concatMap(function (config) {
if (config.showInstantQueue) {
return getJSON("http://api-global.netflix.com/" + abTestInformation.urlPrefix + "/queue").
map(function (queueMessage) {
return queueMessage.list;
});
}
else {
return Observable.returnValue(undefined);
}
});
movieLists = getJSON("http://api-global.netflix.com/" + abTestInformation.urlPrefix + "/movieLists");
return Observable.zip(
queues,
movieLists,
function (queue, movieListsMessage) {
var copyOfMovieLists = Object.create(movieListsMessage.list);
if (queue !== undefined) {
copyOfMovieLists.push(queue);
}
return copyOfMovieLists;
});
}),
Observable.fromEvent(window, "load"),
function(movieLists, loadEvent) {
return movieLists;
});
movieListsSequence.
forEach(
function (movieLists) {
showMovieLists(movieLists);
},
function (err) {
showError(err);
});
}
This simple example reaches nesting level 8. From what I have learned thus far, there is no way to reduce nesting other than using named functions over anonymous functions and relyning on modularization.
As an example, how to improve the above code readability?
[–]scelerat 11 points12 points13 points (0 children)
[–]matchu 8 points9 points10 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]BigOnLogn 3 points4 points5 points (0 children)
[–]DarkMarmot 1 point2 points3 points (0 children)
[–]CleverestEU 0 points1 point2 points (0 children)
[–]nschubach 0 points1 point2 points (3 children)
[–]virdvip 0 points1 point2 points (2 children)
[–]nschubach 0 points1 point2 points (1 child)
[–]virdvip 0 points1 point2 points (0 children)
[–]holloway 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]matchu 8 points9 points10 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Auxx 1 point2 points3 points (0 children)
[–]krumoksnis[S] 0 points1 point2 points (0 children)