This package has been deprecated

Author message:

Use webmiddle-component-arraymap

webmiddle-service-arraymap

0.3.0 • Public • Published

webmiddle-service-arraymap

Maps an array into an array of resources by executing a callback on each item.

Install

npm install --save webmiddle-service-arraymap

Usage

import { PropTypes, rootContext } from 'webmiddle';
import ArrayMap from 'webmiddle-service-arraymap';

const MyService = () => (
  <ArrayMap
    name="myResources"
    array={[1, 2, 3]}
    callback={num =>
      <SubService
        name={"resource" + num}
        {/*...*/}
      />
    }
  />
);

rootContext.evaluate(<MyService />)
.then(resource => {
  console.log(resource.name); // "myResources" 
  console.log(resource.contentType); // "application/json"
  console.log(resource.content); // [resource1, resource2, resource3]
});

How it works

In terms of implementation it is similar to the Parallel service, meaning that the items are mapped concurrently.

The service resolves with a JSON resource whose content is the obtained array.

Properties

Name Description
name The name of the returned resource.
limit (optional) An integer for setting the maximum concurrency.
array The array that needs to be mapped.
callback The function to call for each item; it is called with the current array item and its index, and it is expected to return a resource.

Package Sidebar

Install

npm i webmiddle-service-arraymap

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

8.45 kB

Total Files

4

Last publish

Collaborators

  • maluen