Skip to content

Instantly share code, notes, and snippets.

@cwharris
Last active December 12, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwharris/4689355 to your computer and use it in GitHub Desktop.
Save cwharris/4689355 to your computer and use it in GitHub Desktop.
Rx.Observable.combineTemplate takes an object with key/value pairs of observables, and returns an observable which yields objects with key/value pairs of values which have been provided internally using Rx.Observable.combineLatest.
Rx.Observable.combineTemplate = function(sources) {
var keys = [];
var values = [];
for (var key in sources) {
keys.push(key);
values.push(sources[key]);
}
return Rx.Observable.combineLatest(values, function() {
var template = {};
for (var i = 0, len = keys.length; i < len; i++) {
template[keys[i]] = arguments[i];
}
return template;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment