fluxible-plugin-fetchr
Advanced tools
Comparing version 0.3.7 to 0.3.8
@@ -13,39 +13,2 @@ /** | ||
/** | ||
* Collects metadata from the service calls so that they can be used for response headers | ||
* @param service | ||
* @param operation | ||
* @param metaArray | ||
* @returns {Function} The proxy method | ||
*/ | ||
function crudProxy(service, operation, metaArray) { | ||
return function crudProxyMethod() { | ||
debug('service proxy'); | ||
// Faster than calling Array.prototype.slice.call(arguments) | ||
var args = new Array(arguments.length); | ||
for (var i = 0; i < args.length; ++i) { | ||
args[i] = arguments[i]; | ||
} | ||
// replace last argument (callback) with proxy callback | ||
// this is because 'config' is an optional param for services | ||
// thus ensuring the proxy callback is always passed in | ||
var callback = args.pop(); | ||
// create proxy callback to add service meta to the context instance | ||
var proxyCallback = function (err, data, meta) { | ||
debug('service proxy callback', data, meta); | ||
if (meta) { | ||
metaArray.push(meta); | ||
} | ||
callback.apply(null, arguments); | ||
}; | ||
args.push(proxyCallback); | ||
// execute service as usual | ||
service[operation].apply(service, args); | ||
}; | ||
} | ||
/** | ||
* Creates a new fetchr plugin instance with options | ||
@@ -99,3 +62,2 @@ * @param {Object} options configuration options | ||
var uri; | ||
var serviceMeta = []; | ||
@@ -111,6 +73,6 @@ var service = new Fetchr({ | ||
actionContext.service = { | ||
create: crudProxy(service, 'create', serviceMeta), | ||
read: crudProxy(service, 'read', serviceMeta), | ||
update: crudProxy(service, 'update', serviceMeta), | ||
'delete': crudProxy(service, 'delete', serviceMeta), | ||
create: service.create.bind(service), | ||
read: service.read.bind(service), | ||
update: service.update.bind(service), | ||
'delete': service.delete.bind(service), | ||
constructGetXhrUri: function constructGetXhrUri(resource, params, config) { | ||
@@ -129,5 +91,3 @@ config = config || {}; | ||
}; | ||
actionContext.getServiceMeta = function getServiceMeta() { | ||
return serviceMeta; | ||
}; | ||
actionContext.getServiceMeta = service.getServiceMeta.bind(service); | ||
}, | ||
@@ -134,0 +94,0 @@ /** |
{ | ||
"name": "fluxible-plugin-fetchr", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"description": "A plugin for Fluxible applications to provide an isomorphic interface for RESTful services", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"debug": "^2.0.0", | ||
"fetchr": "^0.5.14" | ||
"fetchr": "^0.5.18" | ||
}, | ||
@@ -20,0 +20,0 @@ "devDependencies": { |
@@ -55,5 +55,8 @@ # Fetchr Plugin for Fluxible | ||
Fetchr also contains an express/connect middleware that can be used as your access point from the client. | ||
Fetchr middleware expects that you're using the [`body-parser`](https://github.com/expressjs/body-parser) middleware (or an alternative middleware that populates `req.body`) before you use Fetchr middleware. | ||
```js | ||
var server = express(); | ||
// you need to use body parser middleware before `FetchrPlugin` | ||
server.use(bodyParser.json()); | ||
server.use(pluginInstance.getXhrPath(), pluginInstance.getMiddleware()); | ||
@@ -60,0 +63,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112
15406
181
Updatedfetchr@^0.5.18