-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
Internally at Linn, we use convenience functions for retrieving the href value of a given relation by name.
Backbone.Model.prototype.rel = function (name) {
if (!this.has('links')) {
return null;
}
var link = $.grep(this.get('links'), function (l) { return l.rel == name; });
if (link.length > 0) {
return link[0].href;
}
return null;
};This would be a useful addition to backbone.hypermedia, in addition to a rels function which would return an array of href values based on name:
Backbone.Model.prototype.rels = function (name) {
if (!this.has('links')) {
return [];
}
return $.grep(this.get('links'), function (l) { return l.rel === name; });
};The implementations above are pulled from two separate code bases - in adding this to backbone.hypermedia, I'm sure we can implement the rel function by making use of the rels function to avoid duplication.