Skip to content

Instantly share code, notes, and snippets.

@barrydobson
Last active December 1, 2015 14:27
Show Gist options
  • Save barrydobson/62a9da63e18ce82ac40c to your computer and use it in GitHub Desktop.
Save barrydobson/62a9da63e18ce82ac40c to your computer and use it in GitHub Desktop.
Our implementation of the room rate source chain. It executes the source, then runs through all the modifiers
var Promise = require('bluebird');
module.exports = function roomRateSourceChain(originalSource, modifiers) {
return {
getRoomRates: function () {
var originalArguments = [].slice.call(arguments);
return originalSource.apply(null, originalArguments)
.then(function (roomRates) {
originalArguments.unshift(roomRates);
return Promise.reduce(modifiers, function (resultsFromPrevious, modifier) {
originalArguments[0] = resultsFromPrevious;
return modifier.apply(null, originalArguments);
}, roomRates);
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment