forked from cujojs/rest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract common client bits into a rest/client module
- move client.chain() and client.skip() into the client module - added client.wrap() as the preferred way to apply interceptors to clients - deprecated client.chain(); although it still works it will log a warning - updated docs and examples to use wrap
- Loading branch information
Showing
34 changed files
with
271 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2014 the original author or authors | ||
* @license MIT, see LICENSE.txt for details | ||
* | ||
* @author Scott Andrews | ||
*/ | ||
|
||
(function (define) { | ||
'use strict'; | ||
|
||
define(function (/* require */) { | ||
|
||
/** | ||
* Add common helper methods to a client impl | ||
* | ||
* @param {function} impl the client implementation | ||
* @param {Client} [target] target of this client, used when wrapping other clients | ||
* @returns {Client} the client impl with additional methods | ||
*/ | ||
return function client(impl, target) { | ||
|
||
if (target) { | ||
|
||
/** | ||
* @returns {Client} the target client | ||
*/ | ||
impl.skip = function skip() { | ||
return target; | ||
}; | ||
|
||
} | ||
|
||
/** | ||
* Allow a client to easily be wrapped by an interceptor | ||
* | ||
* @param {Interceptor} interceptor the interceptor to wrap this client with | ||
* @param [config] configuration for the interceptor | ||
* @returns {Client} the newly wrapped client | ||
*/ | ||
impl.wrap = function wrap(interceptor, config) { | ||
return interceptor(impl, config); | ||
}; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
impl.chain = function chain() { | ||
if (console) { | ||
(console.warn || console.log).call(console, 'rest.js: client.chain() is deprecated, use client.wrap() instead'); | ||
} | ||
return impl.wrap.apply(this, arguments); | ||
}; | ||
|
||
return impl; | ||
|
||
}; | ||
|
||
}); | ||
|
||
}( | ||
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); } | ||
// Boilerplate for AMD and Node | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.