Skip to content

Instantly share code, notes, and snippets.

@cburgdorf
Created July 8, 2011 12:57
Show Gist options
  • Save cburgdorf/1071759 to your computer and use it in GitHub Desktop.
Save cburgdorf/1071759 to your computer and use it in GitHub Desktop.
WrapAs/AppendAs RxJS Extensions
Rx.Observable.prototype.WrapAs = function (propertyName) {
return this.Select(function (x) {
var temp = {};
temp[propertyName] = x;
return temp;
});
};
Rx.Observable.prototype.AppendAs = function (propertyName, data) {
return this.Select(function (x) {
if (null !== x && typeof (x) == 'object') {
x[propertyName] = $.isFunction(data) ? data() : data;
return x;
}
else {
var temp = {};
temp[propertyName] = $.isFunction(data) ? data() : data;
return temp;
}
});
};
Rx.Observable.prototype.ConvertProperty = function (propertyFrom, propertyTo, transistorFunc) {
return this.Select(function(x) {
if (x.hasOwnProperty(propertyFrom) && $.isFunction(transistorFunc)) {
x[propertyTo] = transistorFunc(x[propertyFrom]);
}
return x;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment