Package Exports
- @feathers-plus/batch-loader
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@feathers-plus/batch-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
feathers-plus/batch-loader
Reduce requests to backend services by batching calls and caching records.
Installation
npm install @feathers-plus/batch-loader --save
Documentation
Please refer to the batch-loader documentation for more details.
Complete Example
Here's an example of a Feathers server that uses feathers-plus/batch-loader
.
const BatchLoader = require('@feathers-plus/batch-loader');
const { getResultsByKey, getUniqueKeys } = BatchLoader;
const usersBatchLoader = new BatchLoader(
keys => app.service('users').find({ query: { id: { $in: getUniqueKeys(keys) } } })
.then(result => getResultsByKey(keys, result, user => user.id, '!'))
);
app.service('comments').find()
.then(comments => Promise.all(comments.map(comment => {
// Attach user record
return usersBatchLoader.load(comment.userId)
.then(user => comment.userRecord = user);
})))
License
Copyright (c) 2017 John J. Szwaronek
Licensed under the MIT license.