Skip to content

Commit

Permalink
Allow wiring of wire.js rest factory config objects
Browse files Browse the repository at this point in the history
  • Loading branch information
scothis committed Jan 11, 2015
1 parent be078b0 commit 6fa1cac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Change Log
- support for Safari 8, iOS 8.0 and 8.1 (no code changes required, now actively testing)
- transient timeouts via config.transient on rest/interceptor/timeout, allows retry interceptor to wrap timeout
- request.mixin properties attempt setting before before and after opening the request. Some browsers (IE) are sensitive to when the properties are set.
- wire.js rest factory interceptors now wire configuration objects
- normalize responses for linked and embedded resources from application/hal mime converter to always be a ResponsePromise

1.2.0
Expand Down
12 changes: 12 additions & 0 deletions docs/wire.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@ mime: { module: 'rest/interceptor/mime' },
hateoas: { module: 'rest/interceptor/hateoas' },
$plugins: [{ module: 'rest/wire' }]
```

The 'config' object for an interceptor may also use any wire.js facility. If a literal config object is desired, but is being wired in an undesirable way, use the 'literal' wire.js factory to provide the literal config.

```javascript
client: {
rest: [
{ $ref: 'myInterceptor', config: { literal: { module: 'not/a/wire/module/factory' } } },
]
},
myInterceptor: { ... },
$plugins: [{ module: 'rest/wire' }]
```
8 changes: 4 additions & 4 deletions test/wire-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors
* Copyright 2012-2015 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
Expand Down Expand Up @@ -164,7 +164,7 @@
assert.same(client, spec.client.skip());
}).otherwise(fail);
},
'without wiring interceptor configurations': function () {
'wiring interceptor configurations': function () {
var spec, client;
client = function (request) {
return { request: request };
Expand All @@ -174,12 +174,12 @@
rest: {
parent: client,
interceptors: [
{ module: 'rest/interceptor/pathPrefix', config: { $ref: 'basePath', prefix: 'useThisOne' } }
{ module: 'rest/interceptor/pathPrefix', config: { $ref: 'basePath', prefix: 'dontUseThisOne' } }
]
}
},
basePath: {
literal: { prefix: 'dontUseThis' }
literal: { prefix: 'useThisOne' }
},
$plugins: [{ module: 'rest/wire' }]
};
Expand Down
9 changes: 6 additions & 3 deletions wire.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors
* Copyright 2012-2015 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
Expand All @@ -23,8 +23,11 @@
config.interceptors = when.all((Array.isArray(spec) ? spec : spec.interceptors || []).map(function (interceptorDef) {
var interceptorConfig = interceptorDef.config;
delete interceptorDef.config;
return wire(typeof interceptorDef === 'string' ? { module: interceptorDef } : interceptorDef).then(function (interceptor) {
return { interceptor: interceptor, config: interceptorConfig };
return when.all([
wire(typeof interceptorDef === 'string' ? { module: interceptorDef } : interceptorDef),
wire(interceptorConfig)
]).spread(function (interceptor, config) {
return { interceptor: interceptor, config: config };
});
}));

Expand Down

0 comments on commit 6fa1cac

Please sign in to comment.