Skip to content

Instantly share code, notes, and snippets.

@ntilwalli
Created July 2, 2016 13:38
Show Gist options
  • Save ntilwalli/6d6f75027e02caa7f540e81646ba07f3 to your computer and use it in GitHub Desktop.
Save ntilwalli/6d6f75027e02caa7f540e81646ba07f3 to your computer and use it in GitHub Desktop.
Equivalent to rx-combine-latest-obj for xstream
import xs from 'xstream'
export default function combineObj(obj) {
var sources = [];
var keys = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
keys.push(key.replace(/\$$/, ''));
sources.push(obj[key]);
}
}
return xs.combine(...sources).map(function () {
var args = arguments[0]
var argsLength = args.length;
var combination = {};
for (var i = argsLength - 1; i >= 0; i--) {
combination[keys[i]] = args[i];
}
return combination;
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment